Hey Ricardo!
Could you please provide more information? It will be easier and faster to find a solution to your problem. Because my approach was assuming you didn't need to compare the information you got from the API call and the fields in CRM because you used them to make the query in the first place.
And yes I get fields from CRM. In case I have a code inside the form, when changing this field I need to go to the user table and get another code.
This code returns me from the user table and the user ID in the company so I compare this value passing it as a parameter in the API call, the problem is that I'm already getting a direct error, it doesn't even call the method.
1. What does the API return in both success and failure cases? Is it a boolean? Is it an object?
Hello the API of the direct error stating that the method does not exist but exists
2. What do you want to do with the response? Do you just need an alert in case the client already exists? Or do you want to populate some fields with the information you got from the API?
If the answer is yes, I will clear the code field to prevent him from registering the record because he is with someone, otherwise I give an alert and he can register
Below is an example of my code and the error I'm getting from the copier even though the function is set within the field's properties.
function Valida(context)
{
debugger;
var formContext = context.getFormContext();
var OnwerID = formContext.getAttribute("onwerid").getValue()[0].id;
var codigo = formContext.getAttribute("codigo").getValue();
Xrm.WebApi.online.retrieveMultipleRecords("systemuser", "?$select=id&$filter=systemuserid eq " + OnwerID + "").then(
function success(results)
{
for (var i = 0; i < results.entities.length; i++)
{
var id = results.entities[i]["id"];
}
alert(id);
$.ajax({
url: "">api/.../GetPersons + codigo + "&command.id="+ id";
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
async: false,
crossDomain: true,
success: function(data, textStatus, xhr) {
alert("A");
var result = data;
alaert(result);
},
error: function(xhr, textStatus, errorThrown) {
Xrm.Utility.alertDialog(textStatus + " " + errorThrown);
}
});
},
function(error) {
Xrm.Utility.alertDialog(error.message);
}
);
}


Can someone help me?