0

Hi I have created an onClick javascript button "Complete Job" on the custom object "Job".

I have used the below coding:

{!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 + "/";
  }
}
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}'); 
  alert(url);
  window.open(url);
  alert(window.open(url));
  //window.location.href; 
} else {
  alert('Job status is already Complete.Please check with your system 
    administrator
    for more information on this '); 
  }

When I click on the "Complete Job" button a new tab should open where in there will be a button for "Complete Job"

When I click this button the Job Status should change to "Complete".

This functionality is working perfectly in my sandbox org but it is not working in my production org .

I tried to put an "alert(url);" after the declaration of the variable "url"

The url which I am getting should be a tab containing the "Finish job " button .

This is working perfectly in my sandbox org but it is not working in my production org.

Please guide me how to solve this problem

Here Custom Object is "Job"--sked__Job__c and its picklist field is "Job Status"--sked__Job_Status__c

1

1 Answer 1

1

This answer was provided for a question with the title:

window.open(url) does not work in production

It has since been renamed.

I'm pretty sure you don't need the base URL stuff. Removing that and fixing some other stuff (like the spaces in your url string), we get this:

{!REQUIRESCRIPT("/soap/ajax/39.0/connection.js")} 
{!REQUIRESCRIPT("/soap/ajax/39.0/apex.js")}
sforce.connection.sessionId = '{!$Api.Session_ID}';

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");
if (records.length > 0) {
  var url = encodeURI('/flow/Complete_Job_and_JA?JobId={!sked__Job__c.Id }&retURL=/{!sked__Job__c.Id}'); 
  window.open(url, "_blank");
} 
else {
  alert('Job status is already Complete.Please check with your system administrator for more information on this '); 
}
1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .