Absent Member.
Absent Member.
7067 views

SBM Refreshing field values


SBM Question.

Is there a way to get a calculated date field to update (refresh) while on the same form?

I have two date fields,the second field value will calculate based on the first chosen date. The problem I seem to have is. If the user changes the date in the first field ( not update, still on a submit) the second field wont refresh without hitting the OK button to move to the next state. Is there a way to get it to refresh before the transition?
Tags (1)
0 Likes
14 Replies
Highlighted
Absent Member.
Absent Member.

Re: SBM Refreshing field values


Hello Michelle,
Have a look at the Application Engine Plug In JavaScript Reference guide, it will help you.
At the end, there is an example, if you modify it you should be able to achieve what you want.
//Changing Field Properties Based on Date Change
function DueDateChanged()
{
var text = GetFieldValue("DUE_DATE");
var DueDate = new Date();
DueDate.setTime(Date.parse(text));
var NextWeek = new Date();
NextWeek.setDate(NextWeek.getDate()+7);
if (DueDate < NextWeek) {
MakeFieldRequired("EMRG_APPROVER", true);
MakeFieldRequired("EMRG_REASON", true);
}
else {
HideField("EMRG_APPROVER");
HideField("EMRG_REASON");
}
var FixedDate = new Date();
FixedDate.setFullYear(2015,1,1);
if (DueDate > FixedDate) {
alert('Date too far in the future!');
}
}
AddChangeCallback("DUE_DATE", DueDateChanged);
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: SBM Refreshing field values


Thank You! I'll give this a try. Again Thanks
Michelle
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: SBM Refreshing field values


Hi Olivier - I think the example in the reference guide is old, GetFieldValue was changed at some point for Date fields to return a JS Date Object rather than text, so now you can replace the first three lines in the function with just var DueDate = GetFieldValue("DUE_DATE").
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: SBM Refreshing field values


Hi Everyone, Need some help with this javascript. We cant even get it to fire. Is there something we are doing wrong.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: SBM Refreshing field values


First of all, which version of SBM are you using?
The Javascript API was implemented on SBM 2009 R1 (on top of my head)
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: SBM Refreshing field values


Were on 2009 R3
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: SBM Refreshing field values


Where are you implementing the JavaScript? I'd add it in the Visual Design filter on the left hand side of Mashup Composer, under the JavaScripts section, then on your Custom Form's Property Editor, add that JavaScript name.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: SBM Refreshing field values


Thanks for responding. I think we were forgetting to attach it to the form itself.. But I still keep getting the same date and time stamp as the first field:
Is there something wrong with the script ? Any help is appreciated.
function availDateChange()
{
// set the number of days in SLA to 3, or in the future, fetch it from a field
var SLAdays = 3;
// get date text from avail date field
var availText = GetFieldValue("TARGET_DATE_AVAILABLE_ON");
// put into a Date object to manipulate with Date methods
var availDate = new Date();
availDate.setTime(Date.parse(availText));
// create dueDate Date object and give it the correct value
var dueDate = new Date();
dueDate.setDate(availDate.getDate() + SLAdays);
// now set the due date field with the changed value
SetFieldValue("DUE_DATE", dueDate.toString(), "true");
}
AddChangeCallback("TARGET_DATE_AVAILABLE_ON", availDateChange);
function adjustWeekendDue()
{
//get duedate value, convert to Date object and find day of week.
//Adjust if Sat, Sun
var dueText = GetFieldValue("DUE_DATE");
var dueDate = new Date();
dueDate.setTime(Date.parse(dueText));
//weekdays are 0=Sun .. 7=Sat
var wkday = dueDate.getDay();
if (wkday = 0 || wkday = 7){
dueDate.setDate(dueDate.getDate() + 2);
// now set the due date field with the changed value
SetFieldValue("DUE_DATE", dueDate.toString(), "true");
}
// do nothing if already during work week day
}
AddChangeCallback("DUE_DATE", adjustWeekendDue);
0 Likes
Highlighted
Acclaimed Contributor.
Acclaimed Contributor.

Re: SBM Refreshing field values


I can't see anything worng with that, but I don't do a lot of JavaScript these days. Personally, I need a JS error display tool & debugger. Firefox has an ok tool. I also use Chris Pederick's Developer plugin and the DOM Inspector plugin.
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: SBM Refreshing field values


Thanks Paul. I'll look into the links. Thanks for responding.

Regards,

Michelle
0 Likes
Highlighted
Absent Member.
Absent Member.

Re: SBM Refreshing field values


Also remember change events only fire when the User changes something, not when something is changed by script. So if you want your "Compensate for Weekend" function to fire after your first "set due date" function, you'll need to explicitly call it at the end of the first function, or use FireChangeEvent() on the first field at the end of the function to manually "simulate" a change event that will trigger the second function to also fire.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.