How to Get SC Task Closed Date in Flow Designer Script Step

LokeshwarRV
Tera Contributor

Hi Community,

I'm working with Flow Designer and I have a flow triggered by an SC Task. I want to retrieve the closed_at date of that SC Task and use it in a Flow variable called revokeAccess.

// i am using this in my background script to get the closed date help me to get in my flow script

var taskGR = new GlideRecord('sc_task');
if (taskGR.get(fd_data.sys_id)) {
    var closedAt = new GlideDateTime(taskGR.closed_at);
    return closedAt.toString();
}
4 REPLIES 4

GlideFather
Tera Patron

Hi @LokeshwarRV 

 

you should do it via GlideRecord instead of GlideDateTime

_____
No AI was used in the writing of this post. Pure #GlideFather only

Ankur Bawiskar
Tera Patron

@LokeshwarRV 

if the flow trigger is on sc_task you can directly access the closed_at field.

Why to use Flow variable?

IF you still require then

you can use "Set Flow Variables" flow logic and use script to set the value

something like this in the f(x) inline script

return fd_data.trigger.current.closed_at.toString();

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@LokeshwarRV 

Hope you are doing good.

Did my reply answer your question?

💡 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  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

VaishnaviK16371
Tera Contributor

Hi @LokeshwarRV !!

 

Since your flow is already triggered by an SC Task, you don’t need to query the sc_task table again with a GlideRecord. The triggering record is already available in Flow Designer.

 

Best practice (no script required)

  1. Create your flow variable revokeAccess (type: Date/Time).

  2. When setting the value, simply use the data pill:

Trigger → SC Task → Closed at

This directly gives you the closed_at value of the SC Task.

 

If you need to use a Script step

If you want to process the value in a Run Script action, reference the trigger record instead of using a new GlideRecord:

 

 
(function execute(inputs, outputs) {

    if (inputs.task.closed_at) {
        var closedAt = new GlideDateTime(inputs.task.closed_at);
        outputs.revokeAccess = closedAt.getValue();
    }

})(inputs, outputs);

Configuration:

  • Input:
    task → Data pill → Trigger → SC Task

  • Output:
    revokeAccess → Date/Time (or String)

 

Mark this as Helpful if it clarifies the issue.
Accept the solution if this answers your question.

Regards,
Vaishnavi
Associate Technical Consultant