Skip to main content

Command Transformation Scripts

A Command Transformation script can be used to change command properties at runtime. It's only safe to modify agent commands in Command Transformation scripts. It's not safe to modify sub-commands in a Command Transformation script. You should only modify the current command. 

Command Transformation is available on the Extracted Content Tab.

Command Transformation Provide Various Languages for Transformation.

Command Transformation also provides the option to open a Full-Size Editor Window for easy scripting.

Once you click on the Button “Open Full Sized Editor” it will open the Editor in the Full Sized window.

The following are examples for Transforming the content using different scripting languages in the Transformation window.

Regex

The script below extracts the first Word of the content extract.

Interestingly the Sequentum Cloud Provides the feature to Auto Generate Regex for you. Follow the below steps to generate the Regex from the Extracted content.

  • Select the content you want from the extracted content.

  • Once the required content is selected the “Transform” button will change to “Extract Selected”.

  • Click on the “Extract Selected” button and it will generate the Regex for you and will show the result on the right side.

  • Click on the “Transformation” button and it will open the Transformation scripting window where you can see the “Auto Generated” Regex.

  • C#

    The following example extracts the first word of the extracted content.

CODE
public string TransformContent(string content, RunContext context) 
{
    // Extract the first word from the extracted content.
    return content.Split(" ")[0];

}

The script above uses the “content” command which is of “string” type and returns the extracted content only. Most importantly it can’t be updated by scripting. However, the “content” command has some string methods that can be used on the extracted content for modifying the content as per the need. The above script uses the “Split” method to split the content with “ ” as a separator and then uses index “0” to get the first word.

The below code shows the example of getting the Cookies or Proxy, etc.

CODE
public string GetData(RunContext context) 
{
    return context.ActionResult.GetReturnValue("cookie");
}

Note: Please enable the option “Capture response headers and cookie” from the “Browser” property of “URL & link” commands. To get the value of the cookie.

The above code used the “context” command to use the methods to get the “Cookies”. 

  • Python:

    The following example extracts the first word of the extracted content.

    CODE
    from se_scripting_utils import *
    
    def transform_content(content: str, context: RunContext):
    
        return content.split(" ")[0]

The script above uses the “content” command which is of “string” type and returns the extracted content only. Most importantly it can’t be updated by scripting. However, the “content” command has some string methods that can be used on the extracted content for modifying the content as per the need. The above script uses the “Split” method to split the content with “ ” as a separator and then uses index “0” to get the first word.

The below code shows the example of getting the Cookies or Proxy, etc.

Note: Please enable the option “Capture response headers and cookie” from the “Browser” property of “URL & link” commands. To get the value of the cookie.

CODE
from se_scripting_utils import *

def get_data(context: RunContext):

    return context.action_result.get_return_value("cookie")

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.