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 Using a REST Message - enter the endpoint in this format: https://dev126222.service-now.com/api/sn_sc/servicecatalog/items/ ${sys_id} /order_now use variable substitution to populate the sys id. Note the sys id corresponds to the catalog item. - add the HTTP Headers: - add the HTTP Content: example:  { "sysparm_quantity" : "1" , "sysparm_requested_for" : "ruen.catitem.user" , "variables" :{ "test_variable" : "this is a test 1" , "test_variable_2" : "this is a test 2" } } or here's how you could use variable substitution in the content: { "sysparm_quantity" : "1" , "sysparm_requested_for" : "ruen.catitem.user" , "variables" :{ "test_variabl

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 httpStatus = response . getStatusCode ();     gs . print ( 'respon