Need help with script for a Set Values Activity in a Workflow

bostonsnow
Kilo Guru

Hello,

I am looking for help in creating a script for a Run Script activity to set values on the RITM form when a user submits a request. The end goal is to set Assigned To and CI fields on the RITM based on the choice selection the user makes on a variable named "Affected Service". I have the Assigned To working fine using a Set Values activity. However, in my scenario, one person may receive an assignment for several of the choices under Affected Service. So I am hoping to add the Run Script activity to set the CI field based on the variable selection. Something like this...

If Affected Service = Choice 1, then set CI field on RITM to "Choice 1"

If Affected Service = Choice 2, then set CI field on RITM to "Choice 2"

If Affected Service = Choice 3, then set CI field on RITM to "Choice 3"

Please let me know if you have any questions and thank you in advance for your help!

Mike

 

1 ACCEPTED SOLUTION

Allen Andreas
Administrator
Administrator

Hi,

Without getting too complicated (like using a Javascript switch, etc.) ...In the run script activity...you would simply do something like:

if (current.variables.affected_service == 'value or sys_id') {
current.configuration_item = 'sys_id';
} else if (current.variables.affected_service == 'value or sys_id') {
current.configuration_item = 'sys_id';
} else if (current.variables.affected_service == 'value or sys_id') {
current.configuration_item = 'sys_id';
}

So that's assuming the variable "Affected Service" is named affected_service, if not, please correct that and then place the value or sys_id in the relevant space above.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

View solution in original post

3 REPLIES 3

Allen Andreas
Administrator
Administrator

Hi,

Without getting too complicated (like using a Javascript switch, etc.) ...In the run script activity...you would simply do something like:

if (current.variables.affected_service == 'value or sys_id') {
current.configuration_item = 'sys_id';
} else if (current.variables.affected_service == 'value or sys_id') {
current.configuration_item = 'sys_id';
} else if (current.variables.affected_service == 'value or sys_id') {
current.configuration_item = 'sys_id';
}

So that's assuming the variable "Affected Service" is named affected_service, if not, please correct that and then place the value or sys_id in the relevant space above.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Works perfectly, thanks Allen!

ccajohnson
Kilo Sage

The CI field on the Requested Item [sc_req_item] table is a reference field which points to the Configuration Item [cmdb_ci] table. Because of this, you will need to populate the reference field using the sys_id of the Configuration Item record.

Is the Affected Service variable a Select Box type variable?
Does the Configuration Item record exist?

If both of the above are true, you may be able to change the values of Choice 1, 2, and 3 to be the SysID values of the appropriate Configuration Item records, then just copy the variable value to the CI field of the RITM record within your workflow. I am using affected_service as the variable name. Feel free to use the variable name you currently use.

current.configuration_item = current.variables.affected_service;

 Let us know if you need further assistance.