Skip to main content

Posts

Showing posts from January, 2024

ServiceNow DECISION TABLES

 ServiceNow DECISION TABLES Use decisions tables to help you reach outcomes that depend on multiple factors. In these tables, each factor is a decision input see  https://docs.servicenow.com/bundle/vancouver-application-development/page/administer/decision-table/concept/decision-table.html

ServiceNow Get All Fields in a GlideRecord

 ServiceNow Get All Fields in a GlideRecord var grAccount = new GlideRecord ( 'x_cls_clear_skye_i_account' ); if ( grAccount . get ( 'sys_id' , '833aeabc1bfbbd10f4b15421604bcb8b' )){ var aFields = grAccount . getFields (); for ( var i = 0 ; i < aFields . size (); i ++) { var glideElement = aFields . get ( i ); if ( glideElement . hasValue ()) { gs . print ( ' ' + glideElement . getName () + '\t' + glideElement ); } } }

ServiceNow How to Get Instance URL Server Side in Scoped App

 ServiceNow How to Get Instance URL Server Side in Scoped App when running the following in a fix script in scoped application  //--check for prod URL and cancel out var env = gs . getProperty ( 'glide.servlet.uri' ); gs . info ( 'rds_del_account_profile_identity::URL=' + env ); if ( env . indexOf ( 'prod.service-now.com' ) > - 1 ) { gs . info ( 'rds_del_account_profile_identity::Not to be run on prod!!' ); } else { gs . info ( 'rds_del_account_profile_identity::URL is OK' ); } you should be able to view the output of gs.info in the logs

ServiceNow retrieve a particular service catalog variable by its name and value

 ServiceNow retrieve a particular service catalog variable by its name and value name (actually the variable sys_id) value var grMTOM = new GlideRecord ( 'sc_item_option' ); var sQuery = 'item_option_new= 818596ea1ba37510af03dce0b24bcbff ^value= test@email.com ' ; grMTOM . addEncodedQuery ( sQuery ); grMTOM . query (); if ( grMTOM . next ()){ gs . print ( grMTOM . sys_id ); gs . print ( grMTOM . value ); }

ServiceNow SAMPLE REST MESSAGE POST - Service Catalog Cart API - How to Order a Catalog Item

 ServiceNow SAMPLE REST MESSAGE POST - Service Catalog Cart API - How to Order a Catalog Item on a Remote Instance see  Service Catalog API  > jump to 'order_now' section OPTION 1: Without a REST Message var request = new sn_ws. RESTMessageV2 (); var sn_instance = 'https://dev223167.service-now.com' ; //var cat_item_sysid= '7198552237b1300054b6a3549dbe5dea'; //--e.g. Adobe Acrobat - item with no variables var cat_item_sysid= '50113326979e4d1021983d1e6253af5e' ; //--e.g. Apple USB-C charge cable - item with 2 variables var catalogapi_url= '/api/sn_sc/servicecatalog/items/' + cat_item_sysid + '/order_now' ; request.setEndpoint(sn_instance + catalogapi_url); request.setHttpMethod( 'POST' ); //--OPTION 1: //var user = 'ruen.test'; //var password = ''; //request.setBasicAuth(user,password); //--OPTION 2: var authentication_type= 'basic' ; var profile_name= '6f7f927f47a346104410edf1d16d4376' ; ...

ServiceNow Service Catalog Cart API error Exception While Reading Request

 ServiceNow Service Catalog Cart API error Exception While Reading Request if you get this http status 500 error when attempting the Service Catalog API POST operation (for example, order_now) com.glide.rest.domain.ServiceException: Exception while reading request Consider what roles your user might need to authenticate (e.g. rest) and also setting this property to 'allow':  glide.sc.req_for.roles.default Consider adding these to the HTTP Headers of the REST Message: Accept application/json Content-Type application/json

ServiceNow Service Catalog Cart API error Invalid Quantity value

 ServiceNow Service Catalog Cart API error Invalid Quantity value if you get this http status 400 error when attempting the Service Catalog API POST operation (e.g. order_now)  {"error":{"message":"Invalid Quantity value","detail":""},"status":"failure"} this can be resolved by specifying the following in the request body of the REST Message POST content box

ServiceNow SAMPLE REST MESSAGE - GET (Service Request Table)

 ServiceNow SAMPLE REST MESSAGE   Service Catalog API REST Message:  to query a ServiceNow instance, use a table API type endpoint and variable substitution for the sys id parameter:   endpoint:   https://dev126222.service-now.com/api/now/table/sc_request/${sys_id} ---   Example Script:  var sSYSID = '6eed229047801200e0ef563dbb9a71c2' ; try {     var r = new sn_ws . RESTMessageV2 ( 'RemoteServiceNowInstance' , 'GET_Request_Status' );     r . setStringParameterNoEscape ( 'sys_id' , sSYSID );     var authentication_type = 'basic' ;     var profile_name = '6016d39dc3ef3510311f1c5ce00131f1' ;     //--override authentication profile     //--authentication type ='basic'/ 'oauth2'     r . setAuthenticationProfile ( authentication_type , profile_name );     var response = r . execute ();     var responseBody = response . getBody ();     var h...