save a updated field in a model by on click javascript button

  • 1
  • Problem
  • Updated 3 years ago
  • Solved
I am trying to update and save a field of my Application object through onclick javascript button .
but the field is not getting updated .Any idea ?
here is the code-
var scModels = skuid.model.getModel('Application');
var scRow = scModels.data[0];
var currentstat=scRow.genesis__Status__c;
alert('current status--------------------- '+currentstat);
var result = sforce.apex.execute('genesis.SkuidPricingCtrl','generatePricing',
{
applicationId : scRow.Id
});
alert(result);
//scModels.updateRow(scRow, {'genesis__Status__c' : "NEW - PRICING GENERATED"});

scRow.genesis__Status__c= "NEW - PRICING GENERATED";
skuid.model.save({callback:function(result){
if(result.totalsuccess){
alert('New Quote Id: ' + scRow.Id); // should be a real SF Id now
}else{
alert('Error: ' + result.insertResults[0]);
console.log(result.insertResults[0]);
}
}});
window.location.reload();

I am not sure this "skuid.model.save" part is correct or not!
Photo of Raya Banerjee

Raya Banerjee

  • 456 Points 250 badge 2x thumb

Posted 3 years ago

  • 1
Photo of Irvin Waldman

Irvin Waldman, Champion

  • 9,006 Points 5k badge 2x thumb
Hi Raya,

I think you want something like this:

// Get reference to our Application model
var appModel = skuid.$M('Application'); 
// Get reference to the first row
var appRow = appModel.getFirstRow(); 
// Log current status
var currentStatus = appRow.genesis__Status__c; 
console.log('Current Status: ' + currentStatus); 
// Call Apex web service to get latest pricing
try {
    var result = sforce.apex.execute(
        'genesis.SkuidPricingCtrl',
        'generatePricing', { 
            applicationId : appRow.Id 
        }
    );
    console.log(result); 
} catch (err) {
    console.log('Error getting pricing: ' + err.description);


// NOTE: Both the row update and save could be performed in the Action Framework
// Update pricing status
appModel.updateRow({
    Id: appRow.Id
}, {
    genesis__Status__c: "NEW - PRICING GENERATED"
});
// Save updates
appModel.save({
    callback: function (result) {
        if (result.totalsuccess) {
             alert('New Quote Id: ' + appRow.Id); 
        } else {
            alert('Error: ' + result.insertResults[0]); 
            console.log(result.insertResults[0]);          
        }
    }
});
 
// Why are you doing this?
window.location.reload(); 
Photo of Raya Banerjee

Raya Banerjee

  • 456 Points 250 badge 2x thumb
AWESOME! It is working !Thank you!
(Edited)