The CreatorCon Call for Content is officially open! Get started here.

How to get dot walk values in servicenow

Manju Shree
Tera Expert

Hi,

I have a requirement where if a user enters release number, the output should be a story's functional task number and its assigned to number. I have to do it through array. 

In the for loop, i'm unable to get the scrum task number and the assigned to value.

 

var release_Num = 'RLSE0010002';
var release_Shortdes = 'Test';
var val = [];
var rel = new GlideRecord('rm_release_scrum');
rel.addQuery('number', release_Num);
rel.addQuery('short_description', release_Shortdes);
rel.query();
if (rel.next()) {
    var id = rel.getUniqueValue();
    var str = new GlideRecord('rm_story');
    str.addQuery('release', id);
    str.query();

    while (str.next()) {
        gs.print("StoryNumber" + " " + "-" + " " + str.number);
        var stask = new GlideRecord('rm_scrum_task');
        stask.addQuery('story', str.sys_id);
        stask.addEncodedQuery('type=4^numberNOT LIKEITG^short_descriptionLIKEFunctional Testing');
        stask.query();

        while (stask.next()) {

            val.push(stask.sys_id + '');
        }
        var value = val.toString();
        var stri = value.split(',');
        for (var i = 0; i < stri.length; i++) {
            
            gs.print(stask.number[i]+' '+stask.assigned_to[i]);
        }



    }

}

 

Kindly help to get the values. Thanks for the response in advance.

 

Best Regards,

Manjushree 

1 ACCEPTED SOLUTION

Deepak Shaerma
Kilo Sage
Kilo Sage

Hi @Manju Shree 

It appears you are encountering an issue when attempting to access and print the scrum task number and assigned to value after collecting all relevant sys_ids in an array. The core problem in your code snippet lies in the misuse of the GlideRecord variable stask inside your for loop, leading to incorrect attempts to index its properties like arrays, which they are not.

Let’s address and adjust the relevant sections of your code to achieve the desired output:

 

var release_Num = 'RLSE0010002';
var release_Shortdes = 'Test';

var rel = new GlideRecord('rm_release_scrum');
rel.addQuery('number', release_Num);
rel.addQuery('short_description', release_Shortdes);
rel.query();

if (rel.next()) {
    var id = rel.getUniqueValue();

    // Initialize stories GlideRecord
    var str = new GlideRecord('rm_story');
    str.addQuery('release', id);
    str.query();

    while (str.next()) {
        gs.print("Story Number: " + str.number);

        // Initialize scrum tasks GlideRecord
        var stask = new GlideRecord('rm_scrum_task');
        stask.addQuery('story', str.sys_id);
        stask.addEncodedQuery('type=4^numberNOT LIKEITG^short_descriptionLIKEFunctional Testing');
        stask.query();

        while (stask.next()) {
            // Instead of storing sys_id, let’s directly store the relevant info
            var assignedToString = stask.assigned_to.nil() ? "Unassigned" : stask.assigned_to.getDisplayValue(); // This checks if assigned_to is empty and handles accordingly
            gs.print("Scrum Task Number: " + stask.number + " Assigned To: " + assignedToString);
        }
    }
}

 

 

Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma

 



View solution in original post

3 REPLIES 3

Deepak Shaerma
Kilo Sage
Kilo Sage

Hi @Manju Shree 

It appears you are encountering an issue when attempting to access and print the scrum task number and assigned to value after collecting all relevant sys_ids in an array. The core problem in your code snippet lies in the misuse of the GlideRecord variable stask inside your for loop, leading to incorrect attempts to index its properties like arrays, which they are not.

Let’s address and adjust the relevant sections of your code to achieve the desired output:

 

var release_Num = 'RLSE0010002';
var release_Shortdes = 'Test';

var rel = new GlideRecord('rm_release_scrum');
rel.addQuery('number', release_Num);
rel.addQuery('short_description', release_Shortdes);
rel.query();

if (rel.next()) {
    var id = rel.getUniqueValue();

    // Initialize stories GlideRecord
    var str = new GlideRecord('rm_story');
    str.addQuery('release', id);
    str.query();

    while (str.next()) {
        gs.print("Story Number: " + str.number);

        // Initialize scrum tasks GlideRecord
        var stask = new GlideRecord('rm_scrum_task');
        stask.addQuery('story', str.sys_id);
        stask.addEncodedQuery('type=4^numberNOT LIKEITG^short_descriptionLIKEFunctional Testing');
        stask.query();

        while (stask.next()) {
            // Instead of storing sys_id, let’s directly store the relevant info
            var assignedToString = stask.assigned_to.nil() ? "Unassigned" : stask.assigned_to.getDisplayValue(); // This checks if assigned_to is empty and handles accordingly
            gs.print("Scrum Task Number: " + stask.number + " Assigned To: " + assignedToString);
        }
    }
}

 

 

Note: Please Mark this Helpful and Accepted Solution. If this Helps you to understand. This will help both the community and me..
- Keep Learning ‌‌
Thanks & Regards 
Deepak Sharma

 



Thanks for your quick response. It worked.

Sohithanjan G
Kilo Sage

Hi @Manju Shree 

Updated Code

var release_Num = 'RLSE0010002';
var release_Shortdes = 'Test';
var val = [];
var rel = new GlideRecord('rm_release_scrum');
rel.addQuery('number', release_Num);
rel.addQuery('short_description', release_Shortdes);
rel.query();

if (rel.next()) {
    var id = rel.getUniqueValue();
    var str = new GlideRecord('rm_story');
    str.addQuery('release', id);
    str.query();

    while (str.next()) {
        gs.print("StoryNumber" + " " + "-" + " " + str.number);
        var stask = new GlideRecord('rm_scrum_task');
        stask.addQuery('story', str.sys_id);
        stask.addEncodedQuery('type=4^numberNOT LIKEITG^short_descriptionLIKEFunctional Testing');
        stask.query();

        while (stask.next()) {
            gs.print(stask.number + ' ' + stask.assigned_to);
        }
    }
}

 

Please mark as Accepted Solution if this solves your query and HIT Helpful if you find my answer helped you. This will help other community mates too..:)