Skip to main content

ServiceNow Building up a JSON Example in Javascript

 

var oResult = {

            "appservice_Development": {

                "sys_id": "",

                "environment": ""

            },

            "appservice_Production": {

                "sys_id": "",

                "environment": ""

            },

            "appservice_Test": {

                "sys_id": "",

                "environment": ""

            },

            "appservice_Staging": {

                "sys_id": "",

                "environment": ""

            },

            "appservice_QA": {

                "sys_id": "",

                "environment": ""

            },

            "appservice_Demonstration": {

                "sys_id": "",

                "environment": ""

            },

            "appservice_DR": {

                "sys_id": "",

                "environment": ""

            }

        };

 

oResult.appservice_Development.environment='devel';

gs.print(oResult.appservice_Development.environment);

 

 

(ServiceNow) 

 

Comments

  1. The article provides a simple and practical example of building a JSON object in JavaScript within ServiceNow. The structure with separate application service environments makes it easy to see how related properties such as sys_id and environment can be organized.

    The example also demonstrates how an individual nested property can be updated directly using dot notation. Setting the environment value for appservice_Development and then printing it provides a straightforward illustration of accessing nested JSON properties through a Javascript Online Course.

    ReplyDelete
  2. The structured object approach is useful when application data needs to be grouped by environment while keeping related values together. Developers can build on these fundamentals when working with JavaScript objects and data structures through Javascript Online Training.

    ReplyDelete
  3. Overall, the concise example makes it easy to understand how JSON-style objects can be created, populated, and accessed in ServiceNow scripting. These JavaScript fundamentals can also be useful when developing data-driven Web Development Projects.

    ReplyDelete

Post a Comment

Popular posts from this blog

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

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 )){...