Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

Script to update Short Description of existing SCTASK - Request Item.Item

CJPeterson
Tera Expert

Hi All, 

Scripting is a bit new to me still. But I worked on a catalog task where Short Description should have been "Task For Non Software Item" but for some of the tasks it had short description of "Task for Non Software Item- with some random numbers/short description" this was fix. 

Now I would like to update all the tasks from the past with the incorrect short description. Would this be possible with a fix script? Or what would be used in this case? 

 

Thanks for any advice. 

1 ACCEPTED SOLUTION

Amit Gujarathi
Giga Sage

HI @CJPeterson ,
I trust you are doing great.
Here's a sample Fix Script to achieve this:

// Query the catalog tasks with the incorrect short description pattern
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('short_description', 'STARTSWITH', 'Task for Non Software Item-');
taskGR.query();

while (taskGR.next()) {
    // Update the short description to the correct format
    taskGR.short_description = 'Task For Non Software Item';
    taskGR.update();
    gs.info('Updated Task: ' + taskGR.number);
}

gs.info('Fix Script completed.');

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi



View solution in original post

2 REPLIES 2

AshishKM
Kilo Patron

Hi @CJPeterson ,

Yes this can be done via fix script. you need to write fix script on table ( sc_task ) with applied filter condition and iterate the result for short description update.

 

Note: For testing purpose test on some fixed task number first, once code result is perfect , run the same for all task.

Use the below condition for single task record.

grSCTASK.addQuery("number", "<SCTASK NUMBER>"); 

 

 

var grSCTASK = new GlideRecord("sc_task");
       // apply the query condition for matched record based on short description
        grSCTASK.addQuery("short_description", "<ENTER THE CURRENT VALUE>");
        grSCTASK.query();
//itrate the resule set
while (grSCTASK.next()){
      // set the new short description 
      grSCTASK.short_description ="<ENTER THE UPDATED VALUE>";
      // update the record in data base
       grSCTASK.update();
}

 

 

 

 

 


Please mark this response as correct and helpful if it helps you can mark more that one reply as accepted solution

Amit Gujarathi
Giga Sage

HI @CJPeterson ,
I trust you are doing great.
Here's a sample Fix Script to achieve this:

// Query the catalog tasks with the incorrect short description pattern
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('short_description', 'STARTSWITH', 'Task for Non Software Item-');
taskGR.query();

while (taskGR.next()) {
    // Update the short description to the correct format
    taskGR.short_description = 'Task For Non Software Item';
    taskGR.update();
    gs.info('Updated Task: ' + taskGR.number);
}

gs.info('Fix Script completed.');

Was this answer helpful?


Please consider marking it correct or helpful.


Your feedback helps us improve!


Thank you!


Regards,


Amit Gujrathi