Populate the record producer variable value to a document template field

TOKALAJ
Tera Contributor

Hi, 

 

I had a requirement to pre-populate a name field on the generated pdf document template with the value added by the end user from the record producer, I tried the below code but it is not working, can anyone guide me on this.

 

TOKALAJ_0-1743510001786.png

 

 

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@TOKALAJ 

I have worked on it recently and was able to fetch variable value in script of the template.

Is that variable present in MRVS or Single Row?

If in single row then it should work

If it's in MRVS then you can get the JSON and then parse and get the value

Did you try to query the record with caseGr.sys_id and then fetch?

var gr = new GlideRecord("table");
gr.addQuery("sys_id", caseGr.sys_id);
gr.query();
if (gr.next()) {
    return gr.variables.first_name.toString();
}
return '';

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

6 REPLIES 6

Community Alums
Not applicable

Hi @Community Alums , thank you for your response, but the above thread is regarding the HTML document template but I need to pre-populate the information on the pdf template 

Ankur Bawiskar
Tera Patron
Tera Patron

@TOKALAJ 

I have worked on it recently and was able to fetch variable value in script of the template.

Is that variable present in MRVS or Single Row?

If in single row then it should work

If it's in MRVS then you can get the JSON and then parse and get the value

Did you try to query the record with caseGr.sys_id and then fetch?

var gr = new GlideRecord("table");
gr.addQuery("sys_id", caseGr.sys_id);
gr.query();
if (gr.next()) {
    return gr.variables.first_name.toString();
}
return '';

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Thank you so much @Ankur Bawiskar , the above solution really worked