Get order guide sys id in the catalog item client script--how to tell in catalog item scripts if part of an order guide or standalone
How to tell in catalog item scripts if part of an order guide or standalone
below does not work in service portal
alert(gel('sysparm_guide').value);
top.location will be nav_to.do?uri=%2Fcom.glideapp.servicecatalog_cat_item_guide_view.do%3Fsysparm_guide%3D7d292af7371c57008ca1138943990e7d%26sysparm_active%3D5ec78e0237a0db008ca1138943990e63
top.location will be nav_to.do?uri=%2Fcom.glideapp.servicecatalog_cat_item_guide_view.do%3Fsysparm_guide%3D7d292af7371c57008ca1138943990e7d%26sysparm_active%3D5ec78e0237a0db008ca1138943990e63
for service portal
top.location will be https://<instance url>/sp?id=sc_cat_item_guide&sys_id=7d292af7371c57008ca1138943990e7d
var res_orderguide=getP();
if (res_orderguide ){
//--form is part of order guide
g_form.setReadOnly('line_manager', true);
g_form.setReadOnly('requested_for', true);
g_form.setReadOnly('job_title', true);
}
function
getP(){
var isPartOfGuide=false;
try{
var urlString=top.location.toString();
//return urlString;
if(urlString.indexOf('sc_cat_item_guide')>-1){
//--service portal view
isPartOfGuide=true;
}
if(urlString.indexOf('sysparm_guide')>-1){
//--standard servicenow view
isPartOfGuide=true;
}
alert(getPVal('sc_cat_item_guide'));//--to get order guide ID--portal friendly
alert(getPVal('sysparm_guide'));//--to get order guide ID--non portal friendly
}catch (ex){
//alert('err');
}
return (isPartOfGuide);
}
function
getPVal (name){
var parms = decodeURI(location.search).split("&").map(makeParmObjList);
if(parms){
parms.forEach(function(item){
//alert(item.field);
//alert(item.value);
});
}
function
makeParmObjList(item){
var keyPair = item.split('=');
return {field: keyPair[0], value: keyPair[1]};
}
//--courtesy of
//--https://community.servicenow.com/community?id=community_blog&sys_id=ec3eea6ddbd0dbc01dcaf3231f9619d6&view_source=searchResult
//--https://www.servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script/
}
}
}
//https://community.servicenow.com/community/develop/blog/2016/11/04/adventures-in-service-portaling-populate-catalog-variable-values-through-the-url
//https://www.servicenowguru.com/scripting/client-scripts-scripting/parse-url-parameters-client-script/
Comments
Post a Comment