How to auto-populate variable or make service portal url unique

Dash2
ServiceNow Employee
ServiceNow Employee

Working on a project involving the software reclamation table, the idea is that when an unlicensed installation is detected, an email is sent to the employee to take action. The email is sent via flow designerScreen Shot 2022-10-14 at 10.28.38 AM.pngScreen Shot 2022-10-14 at 10.41.37 AM.pngScreen Shot 2022-10-14 at 10.42.19 AM.png

These actions include requesting for a new license, submitting proof of license, and uninstalling the application.

 

All of these options are presented as catalog items, and all the catalog items are linked to one variable set. The variables in the variable set are: software (software installation), installed on (device), model, etc, and are all supported by the following script include and client script;

//script include
var newreclaimInfoAjax = Class.create();
newreclaimInfoAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	checkCurrent: function () {
		var obj = {};
		var id = this.getParameter('sysparm_userID');
		var gr = new GlideRecord('samp_sw_reclamation_candidate');
		gr.addQuery('user', gs.getUserID());
		gr.addQuery('justification', 'unlicensed');
		gr.addQuery('state', 12);
		gr.query();
		if (gr.next()) {
			var softwareGr = new GlideRecord('cmdb_software_product_model');
			softwareGr.addQuery('sys_id', gr.getValue('software_model'));
			softwareGr.query();
			softwareGr.next();
			obj.rec_product = softwareGr.getDisplayValue('product');
			obj.rec_model = gr.getDisplayValue('software_model');
			obj.rec_catalog_item = gr.getDisplayValue('product_catalog_item');
			obj.software = gr.getDisplayValue('software_install');
			obj.installed_on = gr.getDisplayValue('cmdb_ci');
			//obj.number = gr.getValue('number');
			obj.justification = gr.getDisplayValue('justification');
			obj.name = gr.getValue('user');
		}
		return JSON.stringify(obj);
	},
	type: 'newreclaimInfoAjax'
});

// catalog client script
function onLoad() {
    //Type appropriate comment here, and begin script below

    var ga = new GlideAjax('global.newreclaimInfoAjax');
    ga.addParam('sysparm_name', 'checkCurrent');
    ga.addParam('sysparm_userID', g_user.userID); // I have used logged in user and sent to ajax
    ga.getXMLAnswer(function(answer){
        var p = JSON.parse(answer);
        //g_form.setValue('name', p.name);
        g_form.setValue('installed_on', p.installed_on);
        g_form.setValue('software', p.software);
		g_form.setValue('number', p.number);
		g_form.setValue('rec_product', p.rec_product);
		g_form.setValue('rec_model', p.rec_model);
		g_form.setValue('rec_catalog_item', p.rec_catalog_item);
    });
} 

Here's view of the catalog item

Screen Shot 2022-10-14 at 10.42.52 AM.png

The current solution works fine if an employee only has one unlicensed install record; because only one record exists.

 

But if the user has more than one record, how can I make the service portal link unique to that particular record and auto-populate the variable with the correct values, right now, when I click on the URL from the Microsoft Project email, the value in the variable still show Macbeth.

How can I ensure that the link in the email for Microsoft Project auto-populate the software variable with Microsoft Project Professional 2016 - en-us?


Would appreciate any assistance on this.

1 件の受理された解決策

Soeren Maucher
Mega Sage

Hello @Dash2

 

I would suggest adding an additional paramter at the end of the URLs pointing to the Catalog Items. In the E-Mail script where the URLs are currently created you can for example add a paramter "software" with the software id of the record, which triggered the E-Mail.
/sp?id=sc_cat_item&sys_id=7405603147269110d3c0c789826d434f&software=ID12345

 

Then on the Catalog Items you can write a Client Script (on load) which will take this paramter from the URL and use it to populate the field values. E.g. 

function onLoad() {
    var url = top.location.href;
    var software_id = new URLSearchParams(url).get("software");
    g_form.setValue('software', software_id);
}

 
I hope this helped! 

Greetings, 
Sören

元の投稿で解決策を見る

2件の返信2

Soeren Maucher
Mega Sage

Hello @Dash2

 

I would suggest adding an additional paramter at the end of the URLs pointing to the Catalog Items. In the E-Mail script where the URLs are currently created you can for example add a paramter "software" with the software id of the record, which triggered the E-Mail.
/sp?id=sc_cat_item&sys_id=7405603147269110d3c0c789826d434f&software=ID12345

 

Then on the Catalog Items you can write a Client Script (on load) which will take this paramter from the URL and use it to populate the field values. E.g. 

function onLoad() {
    var url = top.location.href;
    var software_id = new URLSearchParams(url).get("software");
    g_form.setValue('software', software_id);
}

 
I hope this helped! 

Greetings, 
Sören

Hi Soeren,

 

Thank you, it worked!