I want to check the value of a field in a custom object in a javascript button

  • 1
  • Question
  • Updated 3 years ago
  • Answered
I am writing code for a javascript button.I have a custom object Application and there is a status field in Application .I want to check the value of this field that if(application.status=='pricing generated' then enter into the loop.I am not sure how to get a field of particular object in skuid.please help .Here is the code 

var applicationModel = skuid.model.getModel('Application');alert("applicationModel "+applicationModel);
var applicationRow =  applicationModel.data[0];
alert("applicationRow "+applicationRow);
var appId =applicationRow.Id ; 
var agree = confirm("Are you sure ?");
alert("agree "+agree);
if (agree){
    if( appId.genesis_Status_c=="NEW - PRICING GENERATED"){
    var retVal = sforce.apex.execute("DemooOrgUtils","borrowerAccepted",{app:appId}); 
    window.location.reload();
    }
    else
    alert("Please generate Pricing  ");
}
Photo of Raya Banerjee

Raya Banerjee

  • 456 Points 250 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Moshe Karmel

Moshe Karmel, Champion

  • 8,646 Points 5k badge 2x thumb
Your almost there... Just try this:

var applicationModel = skuid.model.getModel('Application');
alert("applicationModel "+applicationModel);
var applicationRow =  applicationModel.getFirstRow();
alert("applicationRow "+applicationRow);
var appId =applicationRow.Id ; 
var agree = confirm("Are you sure ?");
alert("agree "+agree);
if (agree){
    if(applicationRow.Genesis_Status__c == "NEW - PRICING GENERATED"){
    var retVal = sforce.apex.execute("DemooOrgUtils","borrowerAccepted",{app:appId}); 
    window.location.reload();
    }
    else
    alert("Please generate Pricing  ");
}
Photo of Raya Banerjee

Raya Banerjee

  • 456 Points 250 badge 2x thumb
Thanks for the reply .
But I am still  having a problem here. If I use this 'applicationRow.Genesis_Status__c' and applicationRow.Lending_Product__c are returning Unidentified and always executing the else part.




var applicationModel = skuid.model.getModel('Application');alert("applicationModel "+applicationModel);
var applicationRow =  applicationModel.data[0];
alert("applicationRow "+applicationRow);
var appId =applicationRow.Id;
alert("applicationRow.Id   "+ applicationRow.Id);
alert("Lending_Product__c "+ applicationRow.Lending_Product__c);
alert("status "+ applicationRow.genesis_Status_c); 
var agree = confirm("Are you sure ?");
alert("agree "+agree);
if (agree){
    if( applicationRow.Genesis_Status__c=="NEW - PRICING GENERATED"){
    var retVal = sforce.apex.execute("DemooOrgUtils","borrowerAccepted",{app:appId}); 
    window.location.reload();
    }
    else
    alert("Please generate Pricing  ");
}
(Edited)