Auto-populate catalog item variables from an email notification

neil_b
Tera Guru

Hi,

 

This challenge may be too far-fetched but here goes nothing. Our users submit a request for software license activations and renewals. When a software license is due to expire soon, our users can submit a request, and our catalog has a variable asking the user to indicate whether the request is for a new license or renewal and if renewal, to select the expiring request number. When our users select the previous request number, the rest of the variables on the catalog are automatically populated with information from the previous request. We're able to accomplish this using an On Change client script and a script include. 

 

Client Script:

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading) {
        return;
    }
 if (g_form.getValue('license_type) == 'Renewal') {
        var slRequest = new GlideAjax('sc_task.SoftwareLicenseClientScript);
        slRequest.addParam('sysparm_name', 'getLicenseDetails');
        slRequest.addParam('sysparm_taskID', g_form.getValue('previous_license_number'));
        slRequest.getXML(autopopulateVariables);

function autopopulateVariables(response) {

        var answer = response.responseXML.documentElement.getAttribute("answer");	
        if (answer) {
            var jsonObj = JSON.parse(answer);

            if (jsonObj.previous_version) {
                g_form.setValue('previous_version', jsonObj.previous_version);
            }
            if (jsonObj.license_validity_start_date) {
                g_form.setValue('license_validity_date', jsonObj.license_validity_date);
            }
            if (jsonObj.expected_renewal_date) {
                g_form.setValue('expected_renewal_date', jsonObj.expected_renewal_date);
            }
    }
}

Script Include:

var SoftwareLicenseClientScript= Class.create();
SoftwareLicenseClientScript.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getLicenseDetails: function(previous_license_number) {
        var licenseDetails = {};
        var slID = this.getParameter('sysparm_taskID');
        if (slID) {
            var scTask= new GlideRecord('sc_task');
            if (scTask.get(slID)) {

                if (scTask.variables.previous_version) {
                    licenseDetails .previous_version= scTask.variables.previous_version.toString();
                } else {
                    licenseDetails .previous_version= "";
                }
                if (scTask.variables.license_validity_start_date) {
                    licenseDetails .license_validity_start_date= scTask.variables.license_validity_start_date.toString();
                } else {
                    licenseDetails .license_validity_start_date= "";
                }
                if (scTask.variables.expected_renewal_date) {
                    licenseDetails .expected_renewal_date= scTask.variables.expected_renewal_date.toString();
                } else {
                    licenseDetails .expected_renewal_date= "";
                }
        }
        return JSON.stringify(licenseDetails);
    },

    type: 'SoftwareLicenseClientScript'
});

 

My question is, am I able to accomplish this using a hyperlink or button on an email notification? We've built a flow that notifies users when a license is due to the expire that contains the previous license request number and there is a button on the email that when the user clicks on it, it opens a new tab on the user's browser with the Catalog Item/Record Producer. Currently, users are having to manually select Renewal and manually select the License Request Number and then our client script and script include kicks in to populate the rest of the variables, but I would like to be able to have all the variables automatically populated with information from the previous license request number by just clicking the button on the notification. 

 

If this can be accomplished, can someone point me in the right direction? I can't do a client script on an email notification, but could I use a mail script? I'm not sure how I can store values in a mail script and then when a browser tab opens up, copy the values from the mail script and populate it into the variables on the browser tab.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@neil_b 

in the email which goes, if you are including link to catalog item, then you can send the previous license number as URL parameter and then grab it from URL and then auto populate

somewhat similar solution I shared recently, see that and enhance

need help in auto populating catalog item 1 variable values in to catalog item 2 variables 

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

View solution in original post

10 REPLIES 10

@neil_b 

Hope you are doing good.

Did my reply answer your question?

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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

Hi Ankur, I haven't yet finished implementing your solution. I still need to figure out how to update the script in my email script that generates the URL. In order for the URL to populate with the necessary variables, I need to somehow call the script include that pulls that information of the previous license request from my on-change client script and see how I can glide record the data in my email script.

@neil_b 

no worries.

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

Hi @Ankur Bawiskar I am seeing one issue. I just tried to create the On Load client script to verify proof of concept, and it is working half as expected. It is populating my variables, but it's populating the sys_id of the variables instead of the actual value.

 

Do you know how I can get around this? 

@neil_b 

if your form has variable which has choices then you should pass choice value in URL as parameter and not sysId

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

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