Question: Auto-populate variables based on an email link

yltsai
Mega Guru

To all experts,

Here I am again to search for answers to a request.

There is a Record Producer to generate records for all training requests.

There is an email sent to the manager to ask him/her to submit a detailed request (a catalog item). The detailed request will be reviewed by several groups in the enterprise.

The email to the requester's manager contains the Training ticket number, requester name, date, location, and manager's information. Also it sends the link of the new blank Detailed request catalog item.

Below is the email contents.

Please use the information below and click <a href="some link here" >the link to access Training Request Details</a>.

Number: ${u_number} (from the based training request record)

Full name: ${u_full_name}

Employee ID: ${u_employee_id}

Start date: ${u_training_start}

Date end: ${u_date_end}

Title: ${u_associate_title}

Manager: ${u_manager}

Cost center: ${u_cost_center}

Location: ${u_location}

Department: ${u_department}

The requirement states when the manager click the link in the email to fill out a new detailed request all information in the email should be auto-populated. The manager can just fill out the rest details in a new catalog item. How can I achieve the requirement?

I looked at few posts in the ServiceNow wiki and online articles I tried but it did not do anything. So, I am not sure if that is what I am looking for.

Please advise.

1 ACCEPTED SOLUTION

yltsai
Mega Guru

I tried few more code and parameters fixes in the past couple days and I have resolved the issue now.



I removed the default value of the ticket number and decoded the sys_myparm in %26sys_myparm%3D format.


The default value was overlooked.



Thank you, Michael.


View solution in original post

13 REPLIES 13

Michael Ritchie
ServiceNow Employee
ServiceNow Employee

The URL to the record could contain querystring parameters with your values and then you can create an onLoad client script on your record producer to get the querystring parameters.   This is documented here:


https://www.servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script...


Michael,



Thank you for the reply. As I stated in my question, I have tried the online article and it did nothing for me.


I am posting my implementation of email clickable link below. I appended my ticket number in bold and underlined.



                  Please use the information below and click <a href="some link to my catalog item&sys_myparm=${u_number}" >the link to access Training Request Details</a>



My onLoad catalog client script for the catalog item:


function onLoad() {


    //Type appropriate comment here, and begin script below


    var ticketNum = getParmVal('sys_myparm');


if(ticketNum) {


g_form.setValue('training_num', ticketNum);


}


}




function getParmVal(name) {


var url = document.URL.parseQuery();


if(url[name])


{


return decodeURL(url[name]);


}


else


{


return;


}


}



When the manager clicked the link in the email, it still returns a brand new catalog item without generating any values. I have a script in place when the reference variable training_num is populated and all others should be populated accordingly. The first part failed to get the training ticket number and nothing else would display relevant values.



Any idea?



Thank you,


OK thanks for the further explanation.   You didn't provide exact articles you tried, so wanted to make sure you saw the one.   That article mentions a workaround for getting the query string parameters.   Did you try that?   I did in my instance and it works fine.



function getParameterValue(name) {  


      name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");  


      var regexS = "[\\?&]" + name + "=([^&#]*)";  


      var regex = new RegExp(regexS);  


      var results = regex.exec(top.location);  


      if (results == null) {  


              return "";  


      } else {  


              return unescape(results[1]);  


      }  


}



So with the new function name, this line:


var ticketNum = getParmVal('sys_myparm');



Becomes:



var ticketNum = getParameterValue('sys_myparm');



It works on Desktop too.


Michael,


No. I did not try the reg code. I thought it was for the Service Portal.


I can try it and get back to the post.



Regards,