Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help required with Script for Transform Map

Jason Nicholas
Tera Expert

Hi

 

I have a transform map that without the script does the following after importing all project tasks via a spreadsheet:

 

 

Source.u_line_unique_key > Target.u_unique_ref (Coalesce)

Source.u_start_date > Target.start_date

Source.u_end_date > Target.end_date

 

As part of the mapping I have the following script, what I am trying to achieve is

  • Where the Project Task is NOT in a pending (-5) state ignore altogether
  • If the Task state is pending (-5) then clear the date field
  • However if the Task state is Pending AND the u_set_date on the task is marked as is true then set the dates (I will eventually want it to set it to leave the dates as they are)

I have tried every which way to configure that I can think of but it either 

  • Updates all tasks based on the spreadsheet dates
  • Clears all dates on every project
  • Does nothing

Can anyone advise please

------------------------------------------------------------------------------------------------------------------------------------------

(function transformRow(source, target, map, log, isUpdate) {
    var PTask = new GlideRecord('pm_project_task');
    //  PTask.addQuery('u_set_dates', true);
        PTask.addQuery('state', -5);
        PTask.query();
         
while(PTask.next()){
        if (PTask.u_set_dates == 'true'){
            target.start_date = '01/01/2025';  
            target.end_date = '02/01/2025';
            gs.log('wxy: project found ' + PTask.number + '- ' + target.start_date + ' - ' + target.end_date);
        //  ignore=true;
        }
            target.end_date = '';  
            target.start_date = '';
        //  ignore=false;
                   
    }
   
})(source, target, map, log, action==="update");
------------------------------------------------------------------------------------------------------------------------------------------
 

 

5 REPLIES 5

Awesome! Sounds like just a small adjustment and you should be there! Let me know if you have any other questions or issues.