Integration- submitting request for user I want to check whether that user exits in salesforce?

Prathamesh Chav
Tera Contributor

Hi Team,

 

While submitting any role request for particular user I want to check whether that user exits in SalesForce or not and if not then it should abort submit action.

anyone knows how to achieve this using integration?

 

Thank You,

Best Regards

1 ACCEPTED SOLUTION

@Prathamesh Chav 

for this you need to contact Salesforce team and check the endpoint and what they expect i.e. user id or email so that they can search in their system

Correct

1) configure REST message with correct authentication details etc, endpoint etc

2) pass what salesforce expects i.e. user name and email

3) invoke it via GlideAjax script include use REST Message v2 and onchange will send user id or email and you can use that in your REST Message

4) The endpoint will return success or failure

5) based on that show error message in onChange client script

I hope I have provided enough guidance on the approach.

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Community Alums
Not applicable

Hi,

Yes, The complate code in script include may assist you achieve your requirement:

 

checkUserExistence: function() {

var userEmail = this.getParameter('sysparm_email');
var restMessage = new sn_ws.RESTMessageV2();
var instanceUrl = 'https://yourInstance.salesforce.com'; 
var query = 'SELECT Id FROM User WHERE Email = \'' + userEmail + '\'';restMessage.setEndpoint(instanceUrl + '/services/data/vXX.0/query/?q=' + encodeURIComponent(query));
restMessage.setAuthenticationProfile('SalesforceOAuthProfile');restMessage.setHttpMethod('GET');

var response = restMessage.execute();
var responseBody = response.getBody();
var responseObject = JSON.parse(responseBody);
if (responseObject.records && responseObject.records.length > 0) {
return true; 
} else {
return false; 
}
},


submitRoleRequest: function(userEmail) {
var userExists = this.checkUserExistence(userEmail);
if (!userExists) {
gs.info("User does not exist in Salesforce");
throw new Error("User does not exist in Salesforce. Request aborted.");
}

gs.info("User exists in Salesforce");
}
};

 

Please share the snap of your script, and let us know where you got stuck. previous code provided by me is generic logic for verifying the users unique field on the Salesforce.

You can configure REST Message with the correct endpoint and credentials then use GlideAjax to invoke the REST Message by passing unique field such as email id of the your.