Customizing incident.js and similar forms
Just wanted to share a simple customization as inspiration :)
I wanted the contact phone numbers of the affected user to be visible and clickable at the main form.
When using @mention to notify people I always forget the username and have to scroll up the form so I added a litle helping text above the actionlog comment field :)
app.custom.formTasks.add('Incident', null, function (formObj, viewModel) { formObj.boundReady(function () { //Get Alternate Contact Method input element var contactObject = $('input[name="ContactMethod"]'); //Hide input field contactObject.css("display", "none"); //Insert Business phone and private phone as clickable links contactObject.before('<span id="ContactPhone" class="help-block"><i class="fa fa-phone"></i> Business: <a href="tel:'+ viewModel.RequestedWorkItem.BusinessPhone + '">' + viewModel.RequestedWorkItem.BusinessPhone + '</a> | Private: <a href="tel:'+ viewModel.RequestedWorkItem.HomePhone + '">' + viewModel.RequestedWorkItem.HomePhone + '</a></span>'); //Insert Alternate contact method line and edit icon contactObject.before('<span id="AlternateContact" class="help-block"> <i class="fa fa-info"></i> Alternate: <a href="tel:'+ viewModel.ContactMethod + '">' + viewModel.ContactMethod + '</a> <i id="EditAlternateContact" class="fa fa-edit cursor-pointer" title="Edit Alternate Contact Method"></i></span>'); //If edit icon is clicked -> show input field $('#EditAlternateContact').click(function(){ contactObject.css("display", "inline"); $('#AlternateContact').css("display", "none"); }); //Add @mention help text with affected display name $('label[for="commentBoxEditor"]').append('<span class="help-block" style="font-weight: 100;display: inline;"> ( To Notify affected user write: <span style="color: black;">@' + viewModel.RequestedWorkItem.DisplayName + ' </span>)</span>'); }); });
Comments
Good stuff @Mikkel_Madsen! I really like the Affected User being visible down by the comments. I can definitely relate to needing that information down there!
Nice one @Mikkel_Madsen !
The simple can't be simple for a very long time - just had to make it a bit more advanced 🤣
Added a listener so the phonenumbers and @mention text gets updated when affected user is changed
@Mikkel_Madsen - How can i get the extraProps informations under the Affected User Text field?😀
@Nico_Redepenning - you can set the ExtraProps property on the field in the form definition(ie Incident.js). It looks like this:
{ DataType: "UserPicker", PropertyDisplayName: "AffectedUser", PropertyName: "RequestedWorkItem", Required: false, ExtraProps: "EmployeeId" },
@Nico_Redepenning did you find out how to mange it? 🙂
Added mobile phone to the contacts and only publish numbers if they exist.
Hello everyone,
I am new to altering javascript, but this is exactly what I am looking for. Where would I paste the above code into incident.[js] to make this work in our tickets?
Thanks in advance.
@Ryan_Larsen - It would go into CustomSpace/custom.js.
Yep. Now that you mention it, that makes perfect sense. Thanks!