Save the users last values in a dialog.

Had a case then I needed to do a modification to a report with a custom dialog where the user could make som changes to the information that teh report would show.

I needed the same behavioure as you get from a RunBase class but I needed to use it in a report. Tha solution was to use the xSysLastValue class.
client server public static container getValue(CompanyId _company,
userId _userId, UtilElementType _type, identifiername _elementName
[, identifiername _designName])
The usage is pretty simple, the parameters is used to identify the correct data. One thing to remember is that if you use this method to retrieve the user data for a dialog in a report for example don't use the reports name as _elementName because you can end up with the user data for the report instead.

To save the data you use the:
client server public static void putValue(container _value, CompanyId _company,
userId _userId, UtilElementType _type, identifiername _elementName
[, identifiername _designName])
Example: 

static void SaveLastValues(Args _args)
{
Dialog _dlg;
DialogGroup _dlgGroup;
DialogField _dlgField1;
DialogField _dlgField2;
container _dialogValues;
NoYesId _choice1;
NoYesId _choice2;
;

_dlg = new dialog();

_dlgGroup = _dlg.addGroup("Group");
_dlgField1 = _dlg.addField(typeid(NoYesId),"Choice 1");
_dlgField2 = _dlg.addField(typeid(NoYesId),"Choice 2");

//Get the previouse values
_dialogValues = xSysLastValue::getValue(curExt(), curUserId(), UtilElementType::Job, "SaveLastValue");

//Check if we have previouse values
if(_dialogValues != conNull())
{
_dlgField1.value(conPeek(_dialogValues, 1));
_dlgField2.value(conPeek(_dialogValues, 2));
}

if(_dlg.run())
{
//Save the user choices
_dialogValues = conNull();
_dialogValues += _dlgField1.value();
_dialogValues += _dlgField2.value();

xSysLastValue::putValue(_dialogValues, curExt(), curUserId(), UtilElementType::Job, "SaveLastValue");

//Do what ever
}
}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.