How to transfer record form information to the service catalog (platform display portal screen)

bonsai
Mega Sage
 

I would like to copy the field information from the following record form to the catalog item input form:

 

An important requirement is that the catalog item entry form must be displayed in the platform content frame, not in a separate tab or window.

 

 

test_table_a.pngtest_item_2.png

 

 

 

1. Pass the record's sys_ID to the URL in the UI action.
2. After receiving the sys_ID from the URL in the catalog item's client script, call the script include using Ajax.
3. Use the sys_ID in the script include to identify the record and retrieve field information.
4. Set the value received from the script include in the catalog item's field.

I thought I could copy it this way, but I realized that the sys_ID is not set in the URL at step 2.

Does anyone know a better way to do this?
Unfortunately, I can't share the script.

2 ACCEPTED SOLUTIONS

Tanushree Maiti
Kilo Patron

Hi @bonsai 

 

Use this  sample ui action and  Catalog client script: 

 

function copyToCatalog() {
var sysId = g_form.getUniqueValue();
var caller = g_form.getValue('caller_id');
var catItemSysId = '218151833710100054b6a3549dcf5d6f'; // replace with your catalog sys_id
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + catItemSysId;

// 3. Append data as parameters if you need
url += '&sysparm_caller=' + encodeURIComponent(caller);
url += '&sysparm_source_id=' + encodeURIComponent(sysId);
gs.setRedirect(url);
}


Catalog Client Script:

function onLoad() {
var sys_id = getParmVal('sysparm_source_id');
var caller = getParmVal('sysparm_caller');
//put your logic after getting value
alert(sys_id);
alert(caller)

function getParmVal(name){
var url = document.URL.parseQuery();
if(url[name]){
return decodeURI(url[name]);
} else {
return;
}
}
}

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

View solution in original post

Ankur Bawiskar
Tera Patron

@bonsai 

you can have a UI action on that custom table which opens that catalog item

But it will open in native view only and won't open portal

what's the business requirement here?

Why not take them to portal on click of button on form and auto populate the variables?

https://www.servicenow.com/community/virtual-agent-forum/autopopulate-variable-value-using-ui-action...

https://www.servicenow.com/community/developer-forum/redirect-from-a-ui-action-to-a-catalog-item-and...

https://www.servicenow.com/community/itsm-forum/how-to-populate-incident-number-in-service-catalog-v...

💡 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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

2 REPLIES 2

Tanushree Maiti
Kilo Patron

Hi @bonsai 

 

Use this  sample ui action and  Catalog client script: 

 

function copyToCatalog() {
var sysId = g_form.getUniqueValue();
var caller = g_form.getValue('caller_id');
var catItemSysId = '218151833710100054b6a3549dcf5d6f'; // replace with your catalog sys_id
var url = 'com.glideapp.servicecatalog_cat_item_view.do?sysparm_id=' + catItemSysId;

// 3. Append data as parameters if you need
url += '&sysparm_caller=' + encodeURIComponent(caller);
url += '&sysparm_source_id=' + encodeURIComponent(sysId);
gs.setRedirect(url);
}


Catalog Client Script:

function onLoad() {
var sys_id = getParmVal('sysparm_source_id');
var caller = getParmVal('sysparm_caller');
//put your logic after getting value
alert(sys_id);
alert(caller)

function getParmVal(name){
var url = document.URL.parseQuery();
if(url[name]){
return decodeURI(url[name]);
} else {
return;
}
}
}

Please mark this response as Helpful & Accept it as solution if it assisted you with your question.
Regards
Tanushree Maiti
ServiceNow Technical Architect
Linkedin:

Ankur Bawiskar
Tera Patron

@bonsai 

you can have a UI action on that custom table which opens that catalog item

But it will open in native view only and won't open portal

what's the business requirement here?

Why not take them to portal on click of button on form and auto populate the variables?

https://www.servicenow.com/community/virtual-agent-forum/autopopulate-variable-value-using-ui-action...

https://www.servicenow.com/community/developer-forum/redirect-from-a-ui-action-to-a-catalog-item-and...

https://www.servicenow.com/community/itsm-forum/how-to-populate-incident-number-in-service-catalog-v...

💡 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  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader