Tuesday, August 7, 2012

Confirm in Standard Interactivity

"Confirm" function in javascript is as powerful as batmobile which work as check for users prior setting or clicking mission critical values. It allows developer to seek user blessings if they want to perform particular operation or not.In ongoing series on Standard Interactivity, here we will discuss usage of "Confirm" and use the result to set/reset values in SI mode.

Problem Statement: In eService Portal, whenever user is changing status values, he/she should be prompted with confirmation message and based on Yes/No values should be set.
Solution: As in HI client it is cake walk solution to implement where one can use BS "PreSetFieldValue" event of BC. However with SI client under question things become different with architectural limitation. The solution is orchestrated using the DOM events available in SI application. Following piece of browser script code is written on onfocus and onchange events. The key here is to determine the sequene of events. onfocus happens before onchange event for Status column.

general declaration:
var preValue;

function Edit_SList__0__Column__Status__onfocus (applet, id)
{
preValue = document.getElementById(id).value; // Fetch current value of status
}

function Edit_SList__0__Column__Status__onchange (applet, id)
{
if(confirm("Are you sure you want to change Status"))
{
document.getElementById("WriteRecord").click();
}
else
{
   document.getElementById(id).value = preValue;
   document.getElementById("WriteRecord").click();
}
 }
This will set/reset the values of status column based on user consensus. A curious mind by now must be thinking can we have Confirm on button click also. Yes we can. My support(ID 745518.1) already have solution to that.

Happy Crunching!!