I have created an onClick javascript button "Complete Job" on my Custom object "Job"
On the click of that button a picklist field "Job Status" should be updated to the value "Complete"
I am able to achieve all the functionalities with the below given code:
{!REQUIRESCRIPT("/soap/ajax/29.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/29.0/apex.js")}
sforce.connection.sessionId= '{!$Api.Session_ID}';
function getBaseURL() {
var url = location.href; // entire url including querystring - also:
window.location.href;
var baseURL = url.substring(0, url.indexOf('/', 14));
if (baseURL.indexOf('http://localhost') != -1)
{
// Base Url for localhost
var url = location.href; // window.location.href;
var pathname = location.pathname; // window.location.pathname;
var index1 = url.indexOf(pathname);
var index2 = url.indexOf("/", index1 + 1);
var baseLocalUrl = url.substr(0, index2);
return baseLocalUrl + "/";
}
else {
// Root Url for domain name
return baseURL + "/";
}
}
if("{!$Profile.Name}"=="System Administrator")
{
var JobstatusCheck = sforce.connection.query("SELECT sked__Job_Status__c
FROM sked__Job__c WHERE Id ='{!sked__Job__c.Id}' AND
sked__Job_Status__c<>'Complete'");
var records = JobstatusCheck.getArray("records");
//alert(records);
if(records.length>0)
{
//alert(records);
var base = getBaseURL();
//alert(base);
var url = base +encodeURI('/flow/Complete_Job_and_JA?JobId=
{!sked__Job__c.Id}&retURL=/{!sked__Job__c.Id}');
window.open(url);
//window.location.href;
}
else
{
alert('Job status is already Complete.Please check with your system
administrator for more information on this');
}
}
else
{
alert('You are not authorized to Complete the Job. Please check with your
System administrator for more information');
}
The functionality is working perfectly but I have to click the Complete Profile button more than once to achieve this .While debugging in the console view I got the error
Refused to set unsafe header "User-Agent"
I didn't find much help regarding this issue .
My requirement is to achieve the task with just one click of the "Complete Job " button .How will I achieve this .Is there something wrong with my code?please assist me.
Here ,
Custom Object is Job(sked__Job__c) and its field (which is to be updated ) is Job Status( sked__Job_Status__c)