Unable to get sys_created_on date from UI Policy Script

neil_b
Tera Guru

We have a record producer that contains a variable "year_end" which has a UI Policy on Target Records only that controls the visibility based on if the request was created in Q4. The purpose of the field is for our users to access historical requests and work them to completion, which is why this policy is on Target Records, not the Catalog Item. 

 

Rather than using UI Policy Actions, we're trying to accomplish this via script because we have specific conditions and you can't write a condition based on a table level field; only a variable. Here is my script:

	var created = g_form.getValue('sys_created_on'); // get the date the request was created
	alert('created is ' + created);
	var date = new Date(created); // convert the value to a date 
	alert('date is ' + date);
	var month = date.getMonth()+1; // extract the month from the date
	alert('month is ' + month);
	if (month = 10 || month = 11 || month = 12){
		g_form.setMandatory('year_end',true);
		g_form.setVisible('year_end',true);
}

 When testing the UI Policy Script, my created variable is showing blank for my request that was already created last year. See below:

created.png

 

Any idea how I can get the value of sys_created_on?

8 REPLIES 8

Hi @neil_b,

maybe I’m misunderstanding, but your question mentions a Record Producer, while the screenshot you shared looks like a table form (workspace). Can you please confirm where script is running on?

 

Regards,

Zakir

The script is running on the Target Record, so yes, essentially the workspace. See below:

script.png

 

Any user can submit the record producer, but our internal department users complete the request within the workspace. The variable is for our internal department to manage if the user submitted the record producer in Q4.

PoonkodiS
Mega Sage

Hi @neil_b ,

I am thinking the same thing as @Mohammed8  said, try this script

var today = new Date();
var month = today.getMonth() + 1; // 1–12

if (month === 10 || month === 11 || month === 12) {
g_form.setMandatory('year_end', true);
g_form.setVisible('year_end', true);
} else {
g_form.setMandatory('year_end', false);
g_form.setVisible('year_end', false);
}

 

Regards,

Poonkodi

Hi @PoonkodiS in this case, the request was already created. It was created in November of last year so it should already have that date as a value. 

 

The purpose of the field is for our users to access historical requests and work them to completion.