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
Ben4817Ben4817 

Updating a field using S-Control


This will reflect my novice status, but I am just trying to build a button that will update the Serial Number on an Asset.  I've tried looking for examples and can't find anything that solves my problem.  The button Executes JavaScript and the Content Source is OnClick JavaScript.  Following is the code that I am using, but when I click the button, I get a syntax error:

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

function updateSerial()
{
var record = new sforce.SObject("Asset");
var newRecords = [ ]; 

record.SerialNumber = {!Account.Product_ID__c};

newRecord.push(c);

result = sforce.connection.update(newRecord);

window.location.reload();
}

I'm sure that once I get this figured out, I'll be able to do most of the rest of what I need to do.  Thanks in advance for any help!

cheenathcheenath
What error do you get?

record.SerialNumber = {!Account.Product_ID__c};

SerialNumber is a string? Then this should look like:

record.SerialNumber = "{!Account.Product_ID__c}";


Ben4817Ben4817
I believe that Serial Number is a string.  It is a standard field on the Asset and says it is type Text(80).  I tried modifying the code as suggested, but still got the same error.  It reads: "A problem with the OnClick JavaScript for this button or link was encountered:         syntax error"  Thanks for your quick reply!
cheenathcheenath
That error message is not very helpful. Use firefox browser with firebug plugin.
It should be able to give you better error message with line number, etc.



Ben4817Ben4817
I feel kind of dumb now, sorry!  I installed the firebug plugin but can't figure out exactly where the find the error message.  Now when I click on the button, nothing happens at all.
cheenathcheenath
Make sure firebug is enabled. It will show a green tick icon in the bottom right (status bar).
Click on this to see the error messages.


Ben4817Ben4817
I have it on and running, but it doesn't pop up with any errors.  It is split into two windows, and on the left, HTML is selected and the following lines seem to pertain to the button:

<input class="btn" type="button" title="Update" onclick="if (window.invokeOnClickJS_00b50000000mKvC) window.invokeOnClickJS_00b50000000mKvC(this); else if (parent.window.invokeOnClickJS_00b50000000mKvC) parent.window.invokeOnClickJS_00b50000000mKvC(this); return false" name="update" value="Update"/>

I'm sure that doesn't help you too much, but I don't know what else to grab.

Really, all I'm trying to do with this is to duplicate a workflow that I have set up to run on creation of the asset.  The problem is just if the Account Product ID is updated after the Asset is created and I want some way to update the field in the Asset when that happens.
cheenathcheenath
I see. I think you do not have to define a function. Just give the code as script.
Also adding alert will help.

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

alert("here");

var record = new sforce.SObject("Asset");
var newRecords = [ ]; 

record.SerialNumber = {!Account.Product_ID__c};

newRecord.push(c);

result = sforce.connection.update(newRecord);

window.location.reload();



Ben4817Ben4817
Thanks for getting back to me so quickly again.  That sure is nice!  I tried the modified code and got the same error message.  Is there something that I need to do in order to get the script to know that it is updating the Asset that has the button being used?