- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 07:35 PM - edited 11-21-2022 07:40 PM
Hi,
I have added new field to resource_plan table i.e u_type which has the choice values type_capex and type_opex
I am writing a business rule on resource_plan table- Where based on the u_type field value on resource form, the resource_type field of corresponding cost_plan should get updated.
i.e if u_type is 'type_opex' then resource_type of corresponding cost plan should be updated as 'Labor Opex'
In my After Insert Business rule -> I am trying to update the resource_type field of cost_plan table based on the choice selected in current resource plan. But it is not updating as expected. Please help me with what is wrong with the following script:
I think if condition is not getting evaluated properly, I tried putting
if ((current.u_type == 'type_opex')
But no luck. Please help me correct the script.
Thanks,
Anusha
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 08:00 PM - edited 11-21-2022 08:01 PM
Hi @Anusha_Rao ,
did you try putting some logs into the script and see if the "==" operator is working or not, also try to print current.getValue("u_type ") in the logs, you can use gs.info() function for that.
And in the line 7, don't use current.number, you should be using current.getUniqueValue(), this will give you the sys_id of the field, as it is present as reference field in the cost plan table.
Something as for line 7:
gr.addQuery("resource_plan", current.getUniqueValue());
Aman Kumar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 08:00 PM - edited 11-21-2022 08:01 PM
Hi @Anusha_Rao ,
did you try putting some logs into the script and see if the "==" operator is working or not, also try to print current.getValue("u_type ") in the logs, you can use gs.info() function for that.
And in the line 7, don't use current.number, you should be using current.getUniqueValue(), this will give you the sys_id of the field, as it is present as reference field in the cost plan table.
Something as for line 7:
gr.addQuery("resource_plan", current.getUniqueValue());
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 08:36 PM - edited 11-21-2022 08:42 PM
@Aman Kumar S I am newbie to ServiceNow, Please share some light on reference fields. So for all the reference fields in the table sys_id is used to access the corresponding record?
Why shouldn't we compare the value of the fields instead of sys_id since values are going to be the same?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-21-2022 08:47 PM
Yes, so talking about reference fields, it is just a field type which is used to store records from some table, and how do you identify a particular record in SN is by sys_id.
So for example, if you observe Users table and if you check department or company field on it, it will be pointing to some record sitting on its respective table, and to verify what value is exactly is stored on the user form, you can do Right click on header of the form and "Show XML" and search for the field name, you will find sys_id there.
Here in your case, you also have resource plan field present on the cost plan form, which denotes a record sitting in resource plan table, so the same sys_id will be reflected there.
Let me know, if it gives you an understanding.
Aman Kumar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-22-2022 06:28 AM
Yes @Aman Kumar S I understood your point. Thank you.