workflow

mahesh009
Tera Contributor

I want to set the short description of an RITM dynamically based on the operation and the account name variables in the form. The short description format is 

operation + 'for' + account name.

How can I achieve this through workflow run script

3 ACCEPTED SOLUTIONS

Sai Krishna6147
Mega Guru

Hi @mahesh009 

Please follow the steps:

  1. Create a custom table with two fields  
    a)catalog item 
    b)script .
  2. Create a record in the table and for catalog item select required item and for script write the dynamic script to assign short description.
  3. Now from workflow run script glide the table record and evaluate the script field.

 Example:
           lets the custom created table is 

 

"u_dynamic_ritm_description_condition"

 


           now the catalog item field value assigned to required item and for script you can us

 

current.short_description = current.variables.operation.getDisplayValue() + ' for ' +current.variables.account_name.getDisplayValue(); 

 

      then use below script in workflow run script.

 

         var grDesc = new GlideRecord('u_dynamic_ritm_description_condition');
            if (grDesc.get('u_catalog_item', current.cat_item)) {
               var evaluator = new GlideScopedEvaluator();
               evaluator.putVariable('current', current);
               evaluator.evaluateScript(grDesc, 'u_advanced_script');

 

View solution in original post

VishaalRanS
Tera Guru

Hi  @mahesh009 

 

Step 1: Create a Custom Table
Create a custom table with two fields:

  1. Catalog Item
  2. Script

Step 2: Add a Record
Add a record to the table. For the Catalog Item field, select the desired item. In the Script field, write a dynamic script to set the short description.

Step 3: Run the Script from Workflow
Use the workflow to run the script, accessing the table record and evaluating the script field.

 

Example:
Assume the custom table is named u_dynamic_ritm_description_condition. Assign the required item to the Catalog Item field and use the following script in the Script field:

 

current.short_description = current.variables.operation.getDisplayValue() + ' for ' + current.variables.account_name.getDisplayValue();

 

Then, in your workflow run script, use the following code:

 

var grDesc = new GlideRecord('u_dynamic_ritm_description_condition');
if (grDesc.get('u_catalog_item', current.cat_item)) {
var evaluator = new GlideScopedEvaluator();
evaluator.putVariable('current', current);
evaluator.evaluateScript(grDesc, 'u_advanced_script');
}

 

Thanks, and Regards

Vishaal

Please mark this response as correct or helpful if it assisted you with your question.

View solution in original post

brahmandlapally
Mega Guru

Hi @mahesh009

In RunScript Add below lines. 

current.short_description = current.variables.operation.getDisplayValue() + ' for ' +current.variables.account_name.getDisplayValue();

current.update();

Thank you.

View solution in original post

4 REPLIES 4

Sai Krishna6147
Mega Guru

Hi @mahesh009 

Please follow the steps:

  1. Create a custom table with two fields  
    a)catalog item 
    b)script .
  2. Create a record in the table and for catalog item select required item and for script write the dynamic script to assign short description.
  3. Now from workflow run script glide the table record and evaluate the script field.

 Example:
           lets the custom created table is 

 

"u_dynamic_ritm_description_condition"

 


           now the catalog item field value assigned to required item and for script you can us

 

current.short_description = current.variables.operation.getDisplayValue() + ' for ' +current.variables.account_name.getDisplayValue(); 

 

      then use below script in workflow run script.

 

         var grDesc = new GlideRecord('u_dynamic_ritm_description_condition');
            if (grDesc.get('u_catalog_item', current.cat_item)) {
               var evaluator = new GlideScopedEvaluator();
               evaluator.putVariable('current', current);
               evaluator.evaluateScript(grDesc, 'u_advanced_script');

 

VishaalRanS
Tera Guru

Hi  @mahesh009 

 

Step 1: Create a Custom Table
Create a custom table with two fields:

  1. Catalog Item
  2. Script

Step 2: Add a Record
Add a record to the table. For the Catalog Item field, select the desired item. In the Script field, write a dynamic script to set the short description.

Step 3: Run the Script from Workflow
Use the workflow to run the script, accessing the table record and evaluating the script field.

 

Example:
Assume the custom table is named u_dynamic_ritm_description_condition. Assign the required item to the Catalog Item field and use the following script in the Script field:

 

current.short_description = current.variables.operation.getDisplayValue() + ' for ' + current.variables.account_name.getDisplayValue();

 

Then, in your workflow run script, use the following code:

 

var grDesc = new GlideRecord('u_dynamic_ritm_description_condition');
if (grDesc.get('u_catalog_item', current.cat_item)) {
var evaluator = new GlideScopedEvaluator();
evaluator.putVariable('current', current);
evaluator.evaluateScript(grDesc, 'u_advanced_script');
}

 

Thanks, and Regards

Vishaal

Please mark this response as correct or helpful if it assisted you with your question.

PrashantLearnIT
Giga Sage

Hi @mahesh009 

 

  1. Script:

    • var ritm = current;: Assigns the current RITM record to the variable ritm.
    • var operation = ritm.variables.operation;: Retrieves the value of the operation variable from the RITM.
    • var accountName = ritm.variables.account_name;: Retrieves the value of the account_name variable.
    • var newShortDescription = operation + ' for ' + accountName;: Concatenates the operation and account_name values with ' for ' to form the desired short description.
    • ritm.short_description = newShortDescription;: Sets the RITM's short description to the newly constructed string.
    • ritm.update();: Saves the changes to the RITM record.
  2. Save and Test the Workflow:

    • Save your changes to the workflow.
    • Test the workflow by initiating a new request for the catalog item and ensuring that the Operation and Account Name fields are populated.
    • Verify that the RITM's short description is updated accordingly after the workflow processes the Run Script activity.

 

********************************************************************************************************
Please appreciate the efforts of community contributors by marking the appropriate response as the correct answer and helpful. This may help other community users to follow the correct solution in the future.

********************************************************************************************************
Cheers,
Prashant Kumar
ServiceNow Technical Architect


Community Profile LinkedIn YouTube Medium TopMate
********************************************************************************************************

brahmandlapally
Mega Guru

Hi @mahesh009

In RunScript Add below lines. 

current.short_description = current.variables.operation.getDisplayValue() + ' for ' +current.variables.account_name.getDisplayValue();

current.update();

Thank you.