Skip to main content

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

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

Popular posts from this blog

Get URL Parameter - server side script (portal or classic UI)

Classic UI : var sURL_editparam = gs . action . getGlideURI (). getMap (). get ( ' sysparm_aparameter ' ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); } Portal : var sURL_editparam = $sp . getParameter ( " sysparm_aparameter " ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); }

ServiceNow check for null or nil or empty (or not)

Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g.  var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord  addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ())  option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){