Unable to set value in fix script

anayna
Tera Contributor

I have a fix script through which i have to set the value of some ritms,but the value is not setting. can somone rectify my code?

 

          var arr = [];
        var gr = new GlideRecord("sc_req_item");
        gr.addEncodedQuery("state=2"); 
        gr.query();
        while(gr.next()) {
            var count = 0;
            var task = new GlideRecord("sc_task");
            task.addQuery("request_item", gr.sys_id);
            taskRec.query();
            var totalCount = task.getRowCount();
            while(task.next()){
                if(task.active.toString() == 'false'){
                    count++;
                }
            }

            if(count== totalCount && totalCount != 0){
           var ab = arr.push(gr.getValue('number'));
            gr.setValue('priority',4);
               
            }
       
gs.print(arr);
       

       
   
1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello @anayna you need to update two lines in your code 

i have mentioned in comments of the script where ever i have updated the code

  var arr = [];
        var gr = new GlideRecord("sc_req_item");
        gr.addEncodedQuery("state=2"); 
        gr.query();
        while(gr.next()) {
            var count = 0;
            var task = new GlideRecord("sc_task");
            task.addQuery("request_item", gr.sys_id);
            task.query(); // updated this to task.query(); from taskRec.query();
            var totalCount = task.getRowCount();
            while(task.next()){
                if(task.active.toString() == 'false'){
                    count++;
                }
            }

            if(count== totalCount && totalCount != 0){
           var ab = arr.push(gr.getValue('number'));
            gr.setValue('priority',4);
               gr.update(); // added this line
            }
       
gs.print(arr);

Hope this helps 

Mark my answer correct if this helps you 

Thanks

View solution in original post

3 REPLIES 3

vikrantsharma
Kilo Guru

Hi, 

After this line:

 gr.setValue('priority',4);

 

you need to add

gr.update();

 

Also, I would recommend to check if it is entering the below loop, as getRowCount() doesn't allow you to iterate:

 

 while(task.next()){
                if(task.active.toString() == 'false'){
                    count++;
                }

Please try and let me know if this helps?

 

Please make it correct if this solves your issue for other to make use it.

Please make it correct or helpful if this solves or help you with your issue for other to make use it.

Thanks & Regards,
Vikrant Sharma

Mohith Devatte
Tera Sage
Tera Sage

Hello @anayna you need to update two lines in your code 

i have mentioned in comments of the script where ever i have updated the code

  var arr = [];
        var gr = new GlideRecord("sc_req_item");
        gr.addEncodedQuery("state=2"); 
        gr.query();
        while(gr.next()) {
            var count = 0;
            var task = new GlideRecord("sc_task");
            task.addQuery("request_item", gr.sys_id);
            task.query(); // updated this to task.query(); from taskRec.query();
            var totalCount = task.getRowCount();
            while(task.next()){
                if(task.active.toString() == 'false'){
                    count++;
                }
            }

            if(count== totalCount && totalCount != 0){
           var ab = arr.push(gr.getValue('number'));
            gr.setValue('priority',4);
               gr.update(); // added this line
            }
       
gs.print(arr);

Hope this helps 

Mark my answer correct if this helps you 

Thanks

SUBHAM AGARWAL
Tera Guru

Hello Ananya,

 

Try adding gr.update() after seeting the state value at end also modify taskRec.query(); to task.query();

Thanks