Friday, October 2, 2015

salesforce Custome button execute javascript and Jquery to update the Record

{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js')}
{!REQUIRESCRIPT('//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/jquery-ui.min.js')}

var newRecArray = [];
if('{!$Profile.Name}' != 'Branch OAC' && '{!$Profile.Name}' != 'System Administrator'){
alert(' Sorry insufficient access to this button !');
}// end of profile if conditin
else{
jQuery(function() {
jQuery('head').append('<link rel="stylesheet" href="//ajax.googleapis.com/ajax/libs/jqueryui/1.10.3/themes/start/jquery-ui.css" type="text/css" />');
var html ='<div id="dialog" title="Enter Comment"> <textarea id="txtn" rows="4" cols="30" id="rsn"></textarea></div>';
if(!jQuery('[id=dialog]').size()){
jQuery('body').append(html);
}

var recordtype= sforce.connection.query("SELECT Name, id from RecordType WHERE Name='LiveStockFinal DE' And SobjectType='Insurance_Detail__c'");
var records = recordtype.getArray("records");
var appRec = new sforce.SObject("Insurance_Detail__c");
appRec.Id= "{!Insurance_Detail__c.Id}";

var currentDate="{!Now()}";

jQuery( "#dialog" ).dialog({
autoOpen: true,
modal: true,
show: {
effect: "explode",
duration: 200
},
hide: {
effect: "explode",
duration: 200
},
buttons: {
"Ok": function() {
var sbComment= $('#txtn').val();

appRec.Status__c='Discrepant';
appRec.RecordTypeId=recordtype.records.Id;
appRec.Sent_Back_Comment__c=sbComment;
appRec.Sent_Back_Date__c= new Date();
newRecArray.push(appRec);
result=sforce.connection.update(newRecArray);

jQuery( this ).dialog( "close" );
window.location.reload( true );
},
Cancel: function() {
jQuery( this ).dialog( "close" );
}
}
});
});
}

No comments:

Post a Comment