Set the records url in URL field

ar1
Kilo Sage

Hi All,
Can anyone please help us on the below requirement.

We wrote below business rule to set the records URL in URL field but some reasons we're getting same url for all the records. But as per the script it should return the url based on the count.

And script is runs on ABC table.


Script:

(function executeRule(current, previous /*null when async*/ ) {

setLink();

function setLink() {
var d = [];
var d1 = [];
var di = new GlideRecord('sn_sec_cmn_src_ci');
di.addEncodedQuery('cmdb_ci.sys_class_name=cmdb_ci_unclassed_hardware^cmdb_ci.x_tsirm_tio_cmdb_asset_attributesISEMPTY^cmdb_ci.operational_status=1^last_scan_dateONLast 90 days@javascript:gs.beginningOfLast90Days()@javascript:gs.endOfLast90Days()^NQcmdb_ci.x_tsirm_tio_cmdb_asset_attributes.sys_updated_onNOTONLast 90 days@javascript:gs.beginningOfLast90Days()@javascript:gs.endOfLast90Days()^cmdb_ci.x_tsirm_tio_cmdb_asset_attributesISNOTEMPTY^cmdb_ci.operational_status=1^last_scan_dateONLast 90 days@javascript:gs.beginningOfLast90Days()@javascript:gs.endOfLast90Days()^cmdb_ci.sys_class_name=cmdb_ci_aix_server');
di.query();
while (di.next())

{
d.push(di.cmdb_ci.toString());

}
var ci = new GlideRecord("cmdb_ci");
ci.addEncodedQuery('sys_class_name=cmdb_ci_unclassed_hardware^operational_status=1');
ci.addQuery('sys_id', 'NOT IN', d);
ci.query();
while (ci.next()) {
var cicount = ci.getRowCount();
gs.info("Count - "+ci.getRowCount());

d1.push(ci.getValue("sys_id"));
}
var link = "";
if (cicount > 0) {
link = "https://abcdev.service-now.com/cmdb_ci.do?sysparm_query=sys_idIN" + d1;
gs.info("link is" + link);
current.u_link = link;
}

current.u_length = current.total_length - current.scanned_length;

}

})(current, previous);

 

Note: In the script log every time we're getting same count.

 

Advance thanks.

 

8 REPLIES 8

Run the below code on the background script

 var d = [];
        var d1 = [];
        var di = new GlideRecord('sn_sec_cmn_src_ci');
        di.addEncodedQuery('cmdb_ci.sys_class_name=cmdb_ci_unclassed_hardware^cmdb_ci.x_tsirm_tio_cmdb_asset_attributesISEMPTY^cmdb_ci.operational_status=1^last_scan_dateONLast 90 days@javascript:gs.beginningOfLast90Days()@javascript:gs.endOfLast90Days()^NQcmdb_ci.x_tsirm_tio_cmdb_asset_attributes.sys_updated_onNOTONLast 90 days@javascript:gs.beginningOfLast90Days()@javascript:gs.endOfLast90Days()^cmdb_ci.x_tsirm_tio_cmdb_asset_attributesISNOTEMPTY^cmdb_ci.operational_status=1^last_scan_dateONLast 90 days@javascript:gs.beginningOfLast90Days()@javascript:gs.endOfLast90Days()^cmdb_ci.sys_class_name=cmdb_ci_aix_server');
        di.query();
        while (di.next()) {
            d.push(di.cmdb_ci.toString());
        }
        var ci = new GlideRecord("cmdb_ci");
        ci.addEncodedQuery('sys_class_name=cmdb_ci_unclassed_hardware^operational_status=1');
        ci.addQuery('sys_id', 'NOT IN', d);
        ci.query();
        while (ci.next()) {
            var cicount = ci.getRowCount();
            gs.info("Count - " + ci.getRowCount());
            d1.push(ci.getValue("sys_id"));
        }
gs.info("d1: -----"+ d1);
        var link = "";
        for (var i = 0; i < d1.length; i++) {
            link = "https://abcdev.service-now.com/cmdb_ci.do?sysparm_query=sys_idIN" + d1[i];
            gs.info("link is: " + link);
//            current.u_link = link;
        }

Hi Abhit,
Thanks for the response.
We're getting all the sys_id's in d1 and same sys_id's are added to url.
Please find the info below:

ar1_0-1673263244420.png

 

Advance thanks.

Update the below for loop in the existing code:

If you want to store the urll of list view then use the first one or if you want to store the form url then use the second link..

var link = "";
        for (var i = 0; i < d1.length; i++) {
            link = "https://abcdev.service-now.com/cmdb_ci.do?sysparm_query=sys_id%3D" + d1[i];//---> this will store the list view of the record
link="https://abcdev.service-now.com/cmdb_ci.do?sys_id=" + d1[i];//--> This url is for the ci form.
            current.u_link = link;
        }

 

Let me know if this works fine for you.

 

 

Abhit

Hi Abhit,
Many thanks for the response.
As i mentioned above we're able to get the correct url with the required sys_id's.
But the problem is /

let us assume that when some "n" numbers of sys_id's are added to url and user clicks on the url.
Example:
only 10 to 30 sys_id's are added to url and when user clicks it's working fine and we're able to see the records.

But if the sys_id's are more than 100+ added to the url then we're getting "URL is too large" error info.
Note: we're getting above mentioned error image.

Thanks.