Updating a date field in Flow Designer

matthew_hughes
Kilo Sage

I'm trying to update the 'Next AMA Due Date' field in my flow designer based on the following requirements:

  • If Enhanced = Date Scoping Completed + 1 Year
  • If Moderate = Date Scoping Completed + 2 Year
  • If Basic = Date Scoping Completed + 3 Year

 

I'm trying to implement the requirements with the following code:

 

matthew_hughes_0-1710405804364.png

 

However, what I'm finding is that it doesn't update the 'Next AMA Due Date' field with the required date. I ran some logs for the 'scopingCompleteDate' and 'amaRating', but nothing is returning to the logs. I was just wondering if somebody has come across this before and what I can do to resolve it.

1 ACCEPTED SOLUTION

Hi @matthew_hughes ,

 

If 2nd step is where you are getting the value and it is a look up record, then you should use 

fd_data._2__look_up_record_current.<field name>
 
Regards,
Deborah Brown
 
Mark the article as helpful and bookmark if you found it useful.

View solution in original post

25 REPLIES 25

Hi @Harish KM  I've tried the following:

 

/*
**Access Flow/Action data using the fd_data object. Script must return a value. 
**Order number is offset by +1 in Error Handling Section.
**Available options display upon pressing "." after fd_data
**example: var shortDesc = fd_data.trigger.current.short_description;
**return shortDesc;
*/
 
var scopingCompleteDate = current.getDisplayValue('u_last_scoping_ama_completed_date');
gs.log('MH: The value of the scopingCompleteDate is: ' + scopingCompleteDate);
 
var gdt = new GlideDateTime(scopingCompleteDate);
 
var amaRating = current.getValue('u_access_management_controls');
gs.log('MH: The value of the amaRating is: ' + amaRating);
 
 
if (amaRating == 'basic') {
return gdt.addDaysLocalTime(1095);
}
else if (amaRating == 'moderate') {
return gdt.addDaysLocalTime(730); 
}
 
else {
return gdt.addDaysLocalTime(365);
}
 
However, when I run it, a message of 'Error: Cannot convert null to an object.,Detail: Cannot convert null to an object.' appears in the execution details

Hi @matthew_hughes replace the below line

var scopingCompleteDate = current.getDisplayValue('u_last_scoping_ama_completed_date');

to

var scopingCompleteDate = current.getValue('u_last_scoping_ama_completed_date');

Regards
Harish

Hi @Harish KM  I've tried that, but it comes back with '

Error: Cannot convert null to an object.,Detail: Cannot convert null to an object.'

Hi @matthew_hughes since it is a flow use like below code

var scopingCompleteDate =fd_data.trigger.current.u_last_scoping_ama_completed_date;

var amaRating = fd_data.trigger.current.u_access_management_controls;

Regards
Harish

Hi @matthew_hughes ,

// Get the value of 'u_last_scoping_ama_completed_date' field
var scopingCompleteDate = fd_data.trigger.current.u_last_scoping_ama_completed_date;
gs.info('The value of scopingCompleteDate is: ' + scopingCompleteDate);

// Create a GlideDateTime object from the retrieved date
var gdt = new GlideDateTime(scopingCompleteDate);

// Get the value of 'u_access_management_controls' field
var amaRating = fd_data.trigger.current.u_access_management_controls;
gs.info('The value of amaRating is: ' + amaRating);

// Define default number of days
var daysToAdd = 365; // Default value for 'other' scenario

// Update number of days based on 'amaRating'
if (amaRating == 'basic') {
daysToAdd = 1095;
} else if (amaRating == 'moderate') {
daysToAdd = 730;
}

// Add days to the date based on the value of 'amaRating'
gdt.addDaysLocalTime(daysToAdd);

// Return the calculated date
return gdt.getDisplayValue();