We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

what is wrong in below script?

Sathwik1
Tera Guru

 

What is wrong in below script?

 
var schedule = new GlideSchedule(inputs.schedule_sys_id);
var start = new GlideDateTime(inputs.starting_date);
var end = new GlideDateTime(inputs.ending_date);
var duration = schedule.duration(start, end);
outputs.duration = duration;
 
Here duration value is fine, perfectly caluclating.. but in backend table it is not setting up.. ending up as "return type is not valid"
 
In the above..my ouput field type is duration... in bacend table as well.. field type is duration.
 
1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron

@Sathwik1 

try this

var schedule = new GlideSchedule(inputs.schedule_sys_id);
var start = new GlideDateTime(inputs.starting_date);
var end = new GlideDateTime(inputs.ending_date);

var dur = schedule.duration(start, end);
outputs.duration = new GlideDuration(dur);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

8 REPLIES 8

marianbruma
Tera Expert

Hi @Sathwik1 

 

schedule.duration() returns a GlideDuration object. Could you confirm where this script is running (Flow Designer Action, Script Include, Business Rule, etc.)?

Also, when you say the backend field is a Duration field, are you writing outputs.duration directly to that field, or is there another step that performs the update?

 

The error "return type is not valid" suggests the value being returned isn't in the format the consumer expects, rather than an issue with the duration calculation itself.

 

Hope it helps,

 

Vikram Reddy
Tera Guru

schedule.duration() returns a GlideDuration object, which Flow Designer cannot store directly.

Return a string instead:

var duration = schedule.duration(start, end);
outputs.duration = duration.getValue();

Configure the output as String. If you only need a readable value, use:

outputs.duration = duration.getDurationValue();

 

Thank you,

Vikram Karety,

Octigo Solutions INC 

Ankur Bawiskar
Tera Patron

@Sathwik1 

try this

var schedule = new GlideSchedule(inputs.schedule_sys_id);
var start = new GlideDateTime(inputs.starting_date);
var end = new GlideDateTime(inputs.ending_date);

var dur = schedule.duration(start, end);
outputs.duration = new GlideDuration(dur);

💡 If my response helped, please mark it as correct and close the thread 🔒— this helps future readers find the solution faster! 🙏

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

Still same error "Invalid return type encountered" @Ankur Bawiskar