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 ); }

URL link in addInfoMessage

var ga=new GlideAjax('gld_HR_ajax'); ga.addParam('sysparm_name', 'checkEmployeeNumber_hrProfile'); ga.addParam('sysparm_hrprofilenumber', g_form.getValue('number')); ga.addParam('sysparm_employeenumber', newValue); ga.getXMLAnswer(function(answer) { if (answer!='undefined' && answer!=''){ var navURL="<a style='text-decoration:underline;color:blue' href=hr_profile.do?sysparm_query=number=" + answer + ">" + answer + "</a><img width='3' src='images/s.gif'/>"; var sMsg='The employee number entered already exists on another HR Profile ' + navURL; //alert(sMsg); g_form.showErrorBox('employee_number', 'error - please check'); g_form.addInfoMessage(sMsg); } });