- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-07-2024 09:11 PM
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
Solved! Go to Solution.
- 614 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-07-2024 10:38 PM
Hi @mahesh009
Please follow the steps:
- Create a custom table with two fields
a)catalog item
b)script . - Create a record in the table and for catalog item select required item and for script write the dynamic script to assign short description.
- 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');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-07-2024 10:50 PM
Hi @mahesh009
Step 1: Create a Custom Table
Create a custom table with two fields:
- Catalog Item
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-08-2024 12:04 AM
Hi @mahesh009
In RunScript Add below lines.
current.short_description = current.variables.operation.getDisplayValue() + ' for ' +current.variables.account_name.getDisplayValue();
current.update();
Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-07-2024 10:38 PM
Hi @mahesh009
Please follow the steps:
- Create a custom table with two fields
a)catalog item
b)script . - Create a record in the table and for catalog item select required item and for script write the dynamic script to assign short description.
- 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');
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-07-2024 10:50 PM
Hi @mahesh009
Step 1: Create a Custom Table
Create a custom table with two fields:
- Catalog Item
- 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-07-2024 11:34 PM
Hi @mahesh009
-
Script:
var ritm = current;
: Assigns the current RITM record to the variableritm
.var operation = ritm.variables.operation;
: Retrieves the value of theoperation
variable from the RITM.var accountName = ritm.variables.account_name;
: Retrieves the value of theaccount_name
variable.var newShortDescription = operation + ' for ' + accountName;
: Concatenates theoperation
andaccount_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.
-
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
********************************************************************************************************
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā10-08-2024 12:04 AM
Hi @mahesh009
In RunScript Add below lines.
current.short_description = current.variables.operation.getDisplayValue() + ' for ' +current.variables.account_name.getDisplayValue();
current.update();
Thank you.