Is there a way to hide pick current user as a requester automatically and hide the requester selection field?

Is it possible to make the change on the ticket entry page so it automatically picks the current user as a requester?
I am evaluating o365 version of Help Desk system. Thanks.

This might be what you’re looking for:

https://plumsail.com/docs/help-desk-o365/v1.x/Configuration%20Guide/Adding%20widget%20to%20SharePoint%20site.html#enable-automatic-sign-in-for-a-widget

1 Like

Hello @Hajime,

I am copying the answer I sent you via the ticketing system here as well:

The code below sets the Requester field to the value of the user currently logged in.

You need to open the New Ticket Form in Forms Designer, click JavaScript button and place the code there:

//Use relative URL to your Helpdesk site:
var siteUrl = '/sites/collaboration/mysite';

var login = "";
var itemID = 0;

SP.SOD.executeOrDelayUntilScriptLoaded((function () { 
    var ctx = new SP.ClientContext.get_current(); 
    var web = ctx.get_web(); 
    ctx.load(web); 
    var user = web.get_currentUser(); 
    user.retrieve(); 
    ctx.executeQueryAsync( 
    function () { 
 login = user.get_title();
 retrieveContactAndFillInRequester(login);
    }); 
}), "SP.js"); 

function retrieveContactAndFillInRequester(login) {

    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('Contacts'); 
    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name="Title" /><Value Type="Text">' + login + '</Value></Eq></Where></Query></View>');
    var collListItem = oList.getItems(camlQuery);   
    clientContext.load(collListItem);   
    clientContext.executeQueryAsync(function() {
   var listItemEnumerator = collListItem.getEnumerator();    
   while (listItemEnumerator.moveNext()) {
       var oListItem = listItemEnumerator.get_current();
itemID = oListItem.get_id();
   }
fd.field('Requester').value({Id:itemID, Title:login});
});          
}

Helpdesk comes without Forms Designer pre-installed, so if you have not installed it yet you need to install it from the SharePoint store first. Simply click Add new app on your site, go to SharePoint store, find Plumsail Forms Designer and click Add it. After that, when you click Design Forms, follow the instructions and install Desktop application.

Best regards,
Anna Dorokhova
Plumsail Team

Hello Anna,
could you please review the code, because it does not work in the Helpdesk Ticket section. When i create a new ticket, the requester field is empty and after the creation of the ticket there is an error. There are missing fields, because the requester-field is not filled from the contacts list.

Within the widget, there is no problem and the requester field is filled correctly.

Another thng is, when i import the widget templates, there is no content in it. The designer- panel is empty!?

Thanks!

Hello Daniel!

The provided code worked for old HelpDesk versions (up to 1.5.10) and it should be used in Forms Designer (for classic forms), not in Plumsail Forms (for modern forms). So could you clarify your use case and requirements for the code? Do you use HelpDesk 2.x.x? Do you need just to put the current user in the Requester field automatically when creating a new ticket on a HelpDesk site?

Regarding the widget forms. Please ensure that you opened Plumsail Forms for editing public (not SharePoint) forms:

изображение

Hello,

we are using Plumsail Forms 1.7.8 (the latest so far) and HelpDesk 2.1.1.

--> Yes this is the UseCase i want to achieve.

--> Thanks, I will try that.

Please follow these steps:

  1. open the New form of the Tickets list for editing in Plumsail Forms:
  2. go to editing JavaScript code:
  3. I used the approach from this article to write the code below:
function setRequester() {

//Get the current user

pnp.sp.profiles.myProperties.get().then(function (result) {

//Assign profile properties to a variable

var props = result.UserProfileProperties;

//Go through the properties

for (var i = 0; i < props.length; i++) {

switch (props[i].Key) {

//If the current property is "UserName"...

case 'UserName':

//...then use it to retrieve an item from the "Contacts" list

pnp.sp.web.lists.getByTitle("Contacts").items.select("ID").top(1).filter("SPUser/UserName%20eq%20%27" + props[i].Value + "%27").get()

.then(res => {

//Use the ID of the item to set the "Requester" field

fd.field('Requester').value = res[0].ID;

});

break;

}

}

});

}

//When the "New" form is rendered...

fd.spRendered(function () {

//...execute the function

setRequester();

});
  1. paste it in the JS editor, save the form, reload your HelpDesk page and check how it works.

Thanks for the quick reply.

It worked. The name for the "contact" list was in my language and not the standard english!

1 Like

Thanks for the confirmation. It will be useful for others to know that the name of the list should correspond to a current locale of the site.