function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
acl5acl5 

List View Filters and Workflow conditions not working when DB Objects are updated via Javascript?

I am using a custom object (This object is the child in a master-detail relationship) with an OnClick Javascript list button.  When a user clicks the custom button, some fields values are updated in the child object and the parent object based on user input.  The database appears to be updated and when I view the objects all the desired updates are visible.

 

My problem is these changes are not recognized by the filters in my custom list views and workflow rules.  Workflow rules are still firing even the the object records no longer meet the entry conditions and the records are visible in list views that the new values should be filtering them out from.

 

Any suggestions?

 

My javascript code is below:

 

 

{!REQUIRESCRIPT("/soap/ajax/13.0/connection.js")}

var records= {!GETRECORDIDS($ObjectType.SalesOrderLineItem__c)};
var newRecords = [];
if (records[0] == null)
{
alert("Please select at least one row") ;
} else {
var testString="";
for(var i =0; i<records.length;i++){
testString = testString+"'"+records[i] +"'";
if(i<(records.length -1)){
testString = testString+',';
}

}

var queryRecords = sforce.connection.query(
"SELECT Name, Id, Quantity__c, Quantity_Shipped__c, Shipped_Date__c From SalesOrderLineItem__c WHERE Id IN(" + testString+ ")");

var lineItems = queryRecords.getArray("records");
var salesOrderId = "{!Sales_Order__c.Id}";
var c = new sforce.SObject("Sales_Order__c");
c.id=salesOrderId;
c.tracking_number__c = prompt("Enter the tracking number");
c.status__c = "6 - Shipped";
newRecords.push(c);

var yesterdayDate = new Date("{!TODAY()}");
yesterdayDate.setDate(yesterdayDate.getDate()-1);
var aDate = (yesterdayDate.getMonth()+1)+ "/"+yesterdayDate.getDate()+"/"+yesterdayDate.getFullYear();

var shipDate =prompt("Enter the date this order was shipped (MM/DD/YYYY)", aDate);

var dateParts=[];
dateParts = shipDate.split("/",3);
var myDate = new Date();
myDate.setDate(dateParts[0]);
myDate.setMonth(dateParts[1]-1);
myDate.setFullYear(dateParts[2]);



for(var i=0;i<lineItems.length;i++){

lineItems[i].Quantity_Shipped__c = lineItems[i].Quantity__c;
lineItems[i].Shipped_Date__c = myDate

}

result1 = sforce.connection.update(lineItems);
result2 = sforce.connection.update(newRecords);


window.location.reload();
}

 

 

Ispita_NavatarIspita_Navatar

Your code seems to be fine, but one will not be able to pinpoint the cause of the behaviour stated by unless you provide the details of the workflow rule.

Please do post it so that we can give an appropriate silution.

 

Thanks