Skip to main content

Write a HTML table as an additional comment to a RITM

 

        var table_html = '<table style="width: 90%; margin: 20px auto; border-collapse: collapse;">';

        var rowIndex = 0;

        // Add table headers with styles

        table_html += '<thead><tr style="background-color: #0F52A2; color: white; font-weight: bold;">' +

            '<th style="padding: 10px; text-align: left;">Name</th>' +

            '<th style="padding: 10px; text-align: left;">Value</th>' +

            '</tr></thead>';

        for (var key in json) {

 

            if (json.hasOwnProperty(key)) {

                rowIndex++;

                var rowColor = (rowIndex % 2 === 0) ? '#f2f2f2' : '#ffffff'; // Alternate colors

 

                table_html += '<tr style="background-color: ' + rowColor + ';">' +

                    '<td style="padding: 8px; border: 1px solid #ddd;">' + key + '</td>' +

                    '<td style="padding: 8px; border: 1px solid #ddd;">' + json[key] + '</td>' +

                    '</tr>';

 

            }

        }

        table_html += '</table>';

        return table_html;

    },

 

    getInfoAttributes: function(json_payload) {

        /*

        Takes a JSON payload with key value pairs and strips out only those with 'info' in their name.

        */

        var json_payload2 = json_payload.replace(/\\"/g, '"'); //strip out the escape backslash

 

        var jsonPayload3 = json_payload2.replace(/\[(.*?)\]/g, function(match) {

            return match.replace(/"/g, "'"); //replace double quotes within square brackets (array) with single quotes

        });

        var result = {};

        var jsonPayload4 = JSON.parse(jsonPayload3);

 

        // Loop through all keys in the JSON object

        for (var key in jsonPayload4) {

            if (jsonPayload4.hasOwnProperty(key) && key.toLowerCase().includes("info")) {

                result[key] = jsonPayload4[key];

            }

        }

 

        return result;

 

    },

   

 

Flow action:

 

 





Comments

Popular posts from this blog

ServiceNow timeout settings for virtual agent chat

  After connecting to live agent User is connected to live agent and not responding to live agent chat or distracted. The below properties controls the timeout settings, the OOB settings for reminder is [180 sec] and for cancelling the chat is [360 sec]. The job is default configured to 2 min so I believe no tweaking is required here.  Property -   com.glide.cs.idle_chat_reminder_timeout                  com.glide.cs.idle_chat_cancel_timeout Scheduled job   - Idle Chat Timer Task   https://community.servicenow.com/community?id=community_article&sys_id=1453b03bdbaad0109e691ea668961929   (ServiceNow ) 

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