July 18, 2015

How to pass arguments by reference in Siebel?

Yes! it is possible to pass arguments by reference to Siebel functions. This technique is not documented in bookshelf and most of developer use this unknowingly while passing true or false to CanInvoke property in WebApplet_PreCanInvokeMethod Event of applets to make controls active or inactive.

Lets see how it works.

Nothing special needs to be done by calling function, only change made is in callee function in declaration of arguments by prefixing & ampersand just like &CanInvoke in PreCanInvokeMethod.


 Lets see an example :

function Service_PreInvokeMethod (MethodName, Inputs, Outputs)
{
if(MethodName == "PassByReferenceTest")
{
var privatePS = TheApplication().NewPropertySet();
privatePS.SetProperty("test","something");
subFunction(privatePS);
TheApplication().RaiseErrorText(privatePS.GetProperty("test"));
return(CancelOperation);
}
return (ContinueOperation);
}

function subFunction (&parameter)
{
parameter.SetProperty("test","TestSuccesful");
}


Above script declares a new property set and sets value of a process property to a string("something"), which is over written("TestSucccesful") by subFunction by directly accessing it through the memory pointer.  When business service is executed RaiseErrorText whill print "TestSuccesful" instead of "something".

 
This trick will potentially save you memory allocation and speed up you code a bit. Please be mindful that this code is just an experiment and should not be used in production environment without proper testing.


Happy coding :)

No comments :

Post a Comment