The Zurich release has arrived! Interested in new features and functionalities? Click here for more

Populate fields from email from inbound email action

daggupati
Tera Contributor

Hi,

How to populate fields from email if it has same name but it is under different section. I am attaching my email. In the email it contains Problem Number 1 , Problem Number 2 and Problem Number 3 under each it has issue and details. So i want to populate Problem Number 1 Issue into Issue 1(In service now form field) and Details into Details 1(Form field) same like this for Problem Number 2 and Problem Number 3.

Any suggestions

email format.JPG

Thanks

6 REPLIES 6

Aravinda YS
Tera Contributor

Refer: https://docs.servicenow.com/bundle/jakarta-servicenow-platform/page/administer/notification/referenc...


Values in an inbound email can set field values in a task record.


Any name:value pair in an inbound email body gets parsed into a variable/value pair in the inbound email script. The name:value pair must be on its own line. Note that most email clients limit the number of characters allowed per line and may truncate excessively long name:value pairs.


To populate a reference field, use setDisplayValue() instead. See Redirecting Emails for an example of using setDisplayValue() in an inbound email action.



Note: The action always generates a lowercase variable name. Also, this functionality does not work on reference fields.


For example, if an email body contains this line:


Foo:bar

The inbound email script creates the variable email.body.foo


with the value of bar


. You can use these variables to create conditions such as:


if(email.body.foo!=undefined){ current.[field]=email.body.foo;}

In this example, the script sets the value of [field]


to the value bar


.


~Hit like/Helpful/answered, if it helped to your issue.


Aravinda


Hi aravind,



Thanks for the reply. Populating field is not a problem, but in my case i have same name fields repeating multiple times under different sections


like Problem Number 1 in that Issue and Details and in the Problem Number 2 again it has Issue and Details.


Please check if this helps.



var arraystr = [];


arraystr = email.body_text.trim().split('Problem Number');


for(var i = 1; arraystr.length >= i; i++){


var prob = [];


prob = arraystr[i].split('\n');


gs.log('details_' + i + ':' + prob[3].split(':')[1]);


gs.log('issue_' + i + ':' + prob[2].split(':')[1]);


}



Hi Shishir,



Instead of log messages, How can i pass the values into the form(Issue1,Issue2,Issue3 and Details1,Details2,Details3).




Thanks