Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Pass parameter through dialog window to record producer.

arshad199110
Tera Contributor

I have created an UI Action within a table which will show a pop up window of record producer.

I need to pass the record number from the opened record to the record producer variable.

 

how to pass value from opened record to the record producer variable?

 

UI Action which I have created has below script:

 

function redirect(){
var dialog = new GlideDialogForm('Open request','com.glideapp.servicecatalog_cat_item_view');
dialog.setTitle('Open request');
dialog.addParm('sysparm_id','6872789f4020c6d47f45743269459c19');
dialog.setSysID(g_form.getUniqueValue());
dialog.addParm('preview','true');
dialog.addParm('ticket', g_form.getUniqueValue());
dialog.render();
}

 

arshad199110_0-1730190811703.png

 

 

3 REPLIES 3

arshad199110
Tera Contributor

@Ankur Bawiskar Any input on this?

Tai Vu
Kilo Patron
Kilo Patron

Hi @arshad199110 

Here are a couple of approaches from mine that you can consider to auto-populate fields when opening the com.glideapp.servicecatalog_cat_item_view UI page.

1. Define an OnLoad client script within the catalog item. Then retrieve the URI and extract the record sys_id to set the variable value accordingly

function onLoad() {
	var uri = top.location.href;
	var recordId = '';
	if(uri.indexOf('demand.do') >= 0){ //replace the table name
		var indexSysId = uri.indexOf('sys_id=') + 7;
		recordId = uri.substring(indexSysId, indexSysId+32);
	}

	if(recordId !== ''){
		g_form.setValue('ticket', recordId); //your ticket reference catalog variable
	}
}

 

2. We customize the UI Page. Clone the UI page and modify it as follows:

HTML

<input type="hidden" id="task_sys_id" name="task_sys_id" value="${sysparm_task_id}"/>

 

Client Script

addLoadEvent(function(){
	var taskId = $('task_sys_id').value;
	g_form.setValue('variables.task', taskId);
});

 

UI Action

//call your customized UI page here
dialog.addParm('sysparm_task_id', g_form.getUniqueValue());

 

Cheers,

Tai Vu

PRASHANTH  K CH
Tera Expert
    //Get Sys ID for current session Record
    automationsysid: function() {
        var sysId = this.getParameter('sysparm_sys_id');
        gs.info('sysparm_sys_id---' + sysId);
        gs.getSession().putClientData("AutomateITID", sysId);
        return sysId + '';
    },


UI action script

function submitrequest() {
    var currentSysId = g_form.getUniqueValue();
    var ga = new GlideAjax('script include name');
    ga.addParam('sysparm_name', 'function name');
    ga.addParam('sysparm_sys_id', currentSysId);
    ga.getXMLAnswer(function(response) {
        var automationSysId = response;

        var dialog = new GlideDialogForm('prompt_modal', 'com.glideapp.servicecatalog_cat_item_view');
        dialog.setTitle('');
        dialog.addParm('sysparm_id', 'item sysID');
        dialog.addParm('sysparm_sys_id', currentSysId);
        dialog.addParm('preview', 'true');
        dialog.setDialogWidth(800);
        dialog.setDialogHeight(350);
        dialog.render();
    });
}




create on load catalog client script

  var ur_sysid=g_user.getClientData("AutomateITID");
  g_form.setValue('univ_rec',ur_sysid);

}