Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Record Producer - Push Variables to Incident if Certain Value is selected

Paul Perilman
Tera Expert

We have a specific offering on the Service Portal for our business applications for reporting incidents. For one of the business applications we would like to collect a few extra fields and have them in the incident when it gets created. I can have the variables added to all of the incidents created by the record producer but when I try to qualify it I can't seem to get the IF condition to be true. We are collecting the CI as a variable and mapping that to the CI field on the Incident. The first two conditions work well and if I remove the If concident the varibales show on any incident created by the record producer. 

 

current.contact_type = 'self-service';
current.u_location = producer.caller_id.location;
var ConfigItem = producer.cmdb_ci;
If (ConfigItem == 'Yardi - Tenant Portal');
    current.work_notes = "Tcode: " + producer.tcode
1 ACCEPTED SOLUTION

Hey, yeah, you want to make sure you remove the semi-colon (if you keep it then you'd see that the work notes appears on all incidents).

If it can't recognize the Config Item value, it most likely isn't the value that you think it is, that's where logging it would help to see its actual value. If the variable is a reference field, then you'd be picking up it's sys_id rather than it's display value. To get it's display value, you can try with .getDisplayValue():

current.contact_type = 'self-service';
current.u_location = producer.caller_id.location;
var ConfigItem = producer.cmdb_ci.getDisplayValue(); // get the display value if cmdb_ci is a variable of type reference
if (ConfigItem == 'Yardi - Tenant Portal') // lower `i` in if, removed semi-colon `;`
    current.work_notes = "Tcode: " + producer.tcode;

 

View solution in original post

4 REPLIES 4

Nick Parsons
Mega Sage

Your syntax isn't right:

  • You should be using a lowercase 'i' in your if statement
  • You have a semi-colon after your if-statement. JavaScript uses blocks { } to denote what's part of the if-statement (which can be optionally left off if you have one statement following the if.
current.contact_type = 'self-service';
current.u_location = producer.caller_id.location;
var ConfigItem = producer.cmdb_ci;
if (ConfigItem == 'Yardi - Tenant Portal') // lower `i` in if, removed semi-colon `;`
    current.work_notes = "Tcode: " + producer.tcode

If this still doesn't work, log (using something like gs.info()) what the value is of ConfigItem and confirm that it is what you think it is (Yardi - Tenant Portal)

Thanks. changing the case helped but with the semi-colon it displays the work note on all the incidents. Can quite seem to get it to recognize the Config Item value. tried both current and producer. Would I need some like a command to get value for the variable?

Hey, yeah, you want to make sure you remove the semi-colon (if you keep it then you'd see that the work notes appears on all incidents).

If it can't recognize the Config Item value, it most likely isn't the value that you think it is, that's where logging it would help to see its actual value. If the variable is a reference field, then you'd be picking up it's sys_id rather than it's display value. To get it's display value, you can try with .getDisplayValue():

current.contact_type = 'self-service';
current.u_location = producer.caller_id.location;
var ConfigItem = producer.cmdb_ci.getDisplayValue(); // get the display value if cmdb_ci is a variable of type reference
if (ConfigItem == 'Yardi - Tenant Portal') // lower `i` in if, removed semi-colon `;`
    current.work_notes = "Tcode: " + producer.tcode;

 

Harish KM
Kilo Patron
Kilo Patron

Hi @Paul Perilman 

If (ConfigItem == 'Yardi - Tenant Portal');

change to

if (ConfigItem == 'Yardi - Tenant Portal');// java script is case sensitive, if and If are different use lowercase letter

Regards
Harish