custom.js, Unable to Implement EventHandling on "RelatedUserInfo.js" ??
Hi,
We have a requirement to enable analysts to edit user details on the "RelatedUserInfo.js" template.
I was going to work towards adding a button on the form, and then writing some event handling on the button to write the changes back to the SCSM database.
For some reason, no matter what I do, I cannot seem to get any event handling working on the RelatedUserInfo template.
In "custom.js" When using the following function...
"app.custom.formTasks.add('<template name>', null, function (formObj, viewModel) {
Where <template name> is the name of the template, I have tried...
- "user"
- "userRelatedInfo"
- "relatedUserInfo"
... but nothing seems to work.
Here is a full example of my test code:
app.custom.formTasks.add('User', null, function (formObj, viewModel) {
formObj.boundReady(function(){
alert("hi");
});
return;
});
Any help with this would be much appreciated!
Regards,
Adrian
Comments
At this time, it is only possible to work in the custom tasks section for:
- Incident
- ServiceRequest
- ChangeRequest
- Problem
- ReleaseRecord
That being said, the custom.js file does load on every page of the Portal. This means you could put your code directly in the custom.js file, but I wouldn't recommend it. If you must work outside of the five areas noted above, the following code would at least narrow down the page before execution:// Code goes here
}
This code is essentially verifying that the URL of the current page is for the RelatedUserInfo page before executing.
Thanks,
Nick
Hi Nick,
Thanks for that.. But this only loads when the form loads.
If I add a button in the form, or change some text in one of the fields on the form, how do I execute code as a result of that event?
I tried adding the following code in custom.js:
viewModel.set("UpdateUserDetails", function() {
alert("test");
});
Yet the button that executes the action "UpdateUserDetails" never triggers this code?
What am I missing here?
Regards,
Adrian
wow thanks Joivan.
It "almost" worked, except I got a debug code error in IE: "unknown method 'apply'" when I clicked on button..
Have I missing something?
Does the same code work for you?
Regards,
Adrian
More specifically I get "Object doesn't support property or method 'apply'" in 'jquery.min.js'
Regards,
Adrian
I just tested by clicking on the title.. and it worked perfectly!
However, When clicking on the button, I get the error above.
I essentially copied and pasted your code as it is. (no change).
And in "RelatedUserInfo.js" I have added the following line to include a clickable button.
{ DataType: "Button", PropertyDisplayName: "Update User Details", ButtonType: "Default", Action: "UpdateUserDetails" },
Any ideas?
Regards,
Adrian
Nice!
That worked perfectly!
Thanks so much for your help... much appreciated.
Also, one last question (which I also posted here https://community.cireson.com/discussion/455/custom-js-problems-working-with-userpicker-fields-objects-e-g-requestedworkitem#latest)
Is there a way I can "update" user properties via the REST API, or is this not currently possible?
By looking at the controller.js, I figured out how to retrieve user properties:
$.get(("/Search/GetObjectPropertiesByProjection?projectionId=490ab845-b14c-1d91-c39f-bb9e8a350933&id=<userGUID>"), function (data) { alert(data[0].FirstName); });
But I cant seem to find a way to update them again back in SCSM??
Any thoughts?
Regards,
Adrian
Got it working (pushing user details back to SCSM) with "/api/V3/Projection/Commit" (yay).
Just doing the final touches now. Once I have finished I will post up the solution for other people to use if they wish.
Thanks for everyone's help!