- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hello Everyone,
Currently, suppose if I am having the variable/value pair on the email body....
example:-
Var1: value1
Var2: value2
Var3: value3
So, now I want to update the field values based on the above variable/value on the incident table, currently we are having the OOTB feature..
if(email.body.foo!=undefined){ current.[field]=email.body.foo;}
but this is not applicable to reference field, is there any other way for this approach??
Thanks in Advance
Utsav
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @UTSAV KUMAR JAI ,
You can parse the variables manually using regex and then resolve references via GlideRecord.
Sample code:
var callerName = extractValue(body, "Caller");
if (callerName) {
var gr = new GlideRecord('sys_user');
gr.addQuery('name', callerName);
gr.query();
if (gr.next()) {
current.caller = gr.sys_id;
} else {
gs.log("Caller not found: " + callerName);
}
}
It will convert value like user name into the required sys_id via GlideRecord lookups.
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
The reason it doesn't work for reference fields is that these fields store a unique identifier (typically a sys_id) of another record, not the display value (like a name or number) that's usually present in the email body
You need to extract the variable/value pairs from the email body.
Once you have the value from the email (e.g., value1 for Var1), you need to query the relevant table to find the corresponding record.
After finding the correct record and its sys_id, you can then update the reference field on the incident record with that sys_id.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
Hi @UTSAV KUMAR JAI ,
You can parse the variables manually using regex and then resolve references via GlideRecord.
Sample code:
var callerName = extractValue(body, "Caller");
if (callerName) {
var gr = new GlideRecord('sys_user');
gr.addQuery('name', callerName);
gr.query();
if (gr.next()) {
current.caller = gr.sys_id;
} else {
gs.log("Caller not found: " + callerName);
}
}
It will convert value like user name into the required sys_id via GlideRecord lookups.
If you found my response helpful, please mark it as ‘Accept as Solution’ and ‘Helpful’. This helps other community members find the right answer more easily and supports the community.
Kaushal Kumar Jha - ServiceNow Consultant - Lets connect on Linkedin: https://www.linkedin.com/in/kaushalkrjha/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
4 weeks ago
The reason it doesn't work for reference fields is that these fields store a unique identifier (typically a sys_id) of another record, not the display value (like a name or number) that's usually present in the email body
You need to extract the variable/value pairs from the email body.
Once you have the value from the email (e.g., value1 for Var1), you need to query the relevant table to find the corresponding record.
After finding the correct record and its sys_id, you can then update the reference field on the incident record with that sys_id.