To call a service, use application.newServiceRequest() to create a service request of type [[scripting_reference_service_message_writer]]. Use the methods on ServiceMessageWriter to create the parameters for the call.
Invoke the service using application.service();
This returns an object of type [[scripting_reference_xpath_evaluator]]. Use the methods on this object to interpret the results.
/** * Find the name of the user identified by userLogonReference */ var req = application.newServiceRequest('GetUserDetails'); req.put('userLogonReferenceDetails',userLogonReference);
application.commit(); var res = application.service(req);
application.commit(); var userName = req.getString('userName');
By default, application.service() adds the credentials of the caller to the service request, and merges errors from the service back into the application object's error fields. Options on application.service() allow you to not pass your credentials or pass other credentials, and to not merge errors back into the application object.
Called services run as a separate unit of work. Because of this, changes to data made in the calling script will not be available to the called service unless you commit before the service() request, and changes to data made in the service will not be available to the calling script unless you commit after the service. Any service that accesses a node may cause updates to nodes (because of derivation), and therefore you should always commit before and after calling a service. Failure to do so can give unexpected results or cause database deadlocks.