+ Start a Discussion
NishanNishan 

Help with a Javascript button

Hi Everyone,

                      I have a javascript button to update certain number fields. It is compiling without errors but not working. Can someone please help me with this

{!requireScript("/soap/ajax/26.0/connection.js")}

var input=prompt("Enter the number");
var query1 = sforce.connection.query("SELECT Id,Number_Added1__c,Number_Added2__c,Number_Added3__c,Number_Added4__c, Number_Added5__c, Number_Added6__c,Number_Added7__c,Number_Added8__c,Number_Added9__c,Number_Added10__c FROM Inventory__c WHERE Id='{!Inventory__c.Id}'");

var records = query1.getArray("records");

var inv = new sforce.SObject("Inventory__c");
inv.Id = "{!Inventory__c.Id}";


if (records[0].Number_Added10__c)
{
window.alert('All 10 slots are full for Stock A. Create the same item with an index name');
}

else if(!records[0].Number_Added1__c)
{
inv.Number_Added1__c = parseFloat(input);
inv.Remaining_Stock__c = records[0].Reamining_Stock__c + parseFloat(input);
}

else if(!records[0].Number_Added2__c)
{ inv.Number_Added2__c = parseFloat(input);
inv.Remaining_Stock__c = records[0].Reamining_Stock__c + parseFloat(input);
}

else if(!records[0].Number_Added3__c)
{ inv.Number_AddedB3__c = parseFloat(input);
inv.Remaining_Stock__c = records[0].Reamining_Stock__c + parseFloat(input);
}

else if(!records[0].Number_Added4__c)
{ inv.Number_Added4__c = parseFloat(input);
inv.Remaining_Stock__c = records[0].Reamining_Stock__c + parseFloat(input);
}

else if(!records[0].Number_Added5__c)
{ inv.Number_Added5__c = parseFloat(input);
inv.Remaining_Stock__c = records[0].Reamining_Stock__c + parseFloat(input);
}

else if(!records[0].Number_Added6__c)
{ inv.Number_Added6__c = parseFloat(input);
inv.Remaining_Stock__c = records[0].Reamining_Stock__c + parseFloat(input);
}

else if(!records[0].Number_Added7__c)
{ inv.Number_Added7__c = parseFloat(input);
inv.Remaining_Stock__c = records[0].Reamining_Stock__c + parseFloat(input);
}

else if(!records[0].Number_Added8__c)
{ inv.Number_Added8__c = parseFloat(input);
inv.Remaining_Stock__c = records[0].Reamining_Stock__c + parseFloat(input);
}

else if(!records[0].Number_Added9__c)
{ inv.Number_Added9__c = parseFloat(input);
inv.Remaining_Stock__c = records[0].Reamining_Stock__c + parseFloat(input);
}

else if(!records[0].Number_Added10__c)
{ inv.Number_Added10__c = parseFloat(input);
inv.Remaining_Stock__c = records[0].Reamining_Stock__c + parseFloat(input);
}


result = sforce.connection.update([inv]);

if(result[0].success == 'true')
{
window.alert('Stock successfully added to Stock A');
}
location.reload();