update description of a task

KouassiP
Tera Contributor

Hello All , 

Due to a business need , i'm trying to update the description of a task in sc_task .

I have created a Dynamic activity linked to this task .

The problem is ;  in the condition to the GlideRecord i have added the sysid of the task , but i have no records .

However , when i run the same script in a background manually , everything is OK . 

I have added a sleep (Maybe the sc_task is not updated when the script is running) and i still have the same result . 

Could you please help me on this topic ?

 

var gr = new GlideRecord ('sc_task');
        gr.addQuery('parent', ritmSysId);
        gr.addQuery('sys_id', taskSysID);
        gr.query();
       
        if (gr.next())
        {  
        gr.setValue  ( 'short_description' , SHDES);
        gr.setValue ('description' , DES);
        gr.update();
        }
    else
    {
        gs.sleep (20000);

        var Tache = new GlideRecord ('sc_task');
        if (Tache.get(taskSysID))
             {
            Tache.setValue  ( 'short_description' , SHDES);
            Tache.setValue ('description' , DES);
            Tache.update();
             }

        else
       
        {
            gs.info('TEST 3' + 'Task not found');
        }
2 REPLIES 2

lpruit2
Kilo Sage

Greetings @KouassiP. Where is "ritmSysid" and "taskSysID" being declared? I do not see them in your script? Have you tried using the .getUniqueValue() method instead? I will include a link to ServiceNow documentation below. 

 

GlideRecord | ServiceNow Developers

Brad Bowman
Kilo Patron
Kilo Patron

In addition to "ritmSysid", "taskSysID", "SHDES", and "DES" not being defined in the script that you posted, you have logic errors / extraneous code.  You don't want or need the sleep, and in the first GlideRecord since you want to return a record with a specific sys_id, wherever you are getting that from, you don't need the 'parent' addQuery line as there is already only one record with that sys_id.  If you want to update the fields with certain values if the parent is populated, and other values if the parent is not populated then do that in the same GlideRecord in an IF block, but as written you're setting the fields to the same (undefined in this case) values in both GlideRecords.  It would help if you describe and show where and how you are using this so we have some context.