Get Value from field in service portal

IK Jeremy Ravel
Kilo Expert

Hello everyone,

In the service portal, I am trying to get the value of one field in my widget, to use this value for redirection

So I have tried in my controller $scope.page.g_form.getValue('u_otp'); , I have field name u_otp in my form but this doesn't seems to works

Does anyone has an idea, how could i do it ?

6 REPLIES 6

andrew_lawlor
Giga Expert

Outside of the Service Catalog, there is currently no clean way to do this (unless I'm not aware of new functionality in Jakarta). I'm assuming you're using the Form Widget, or an extension thereof. You can kludge it up by trying to pull the value directly from the DOM, which no one in their right mind would recommend. The slightly better option is to use an event-driven method, such executing an event and passing data from an onChange Client Script. You can then listen for that event in your Widget Client Script.



For example:



Client Script:


// answer should ideally be your data as JSON


CustomEvent.fire('your_event_name', yourJSONData);



Widget Client Script:



CustomEvent.observe('your_event_name', function(yourData) {


if (yourData) {


// Do your logic.


}


});



Hopefully this helps.


Not really, because sometimes the value is already inside the form, and the user doesn't change it, so I can't record it 😕


Run the script onLoad then.


I would refer to get the value from the server and then use it in controller.