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
dclaardclaar 

Trying to automatically generate some fields on asset edit

We need to automatically generate the serial number on the “new asset” screen (i.e. asset edit), based on several parameters, including date and a function written in javascript.

 

First thought: Add something to the “save” button to do this. Problems (all “near as I can tell, based on trying it, and then googling”):

1)     Can’t modify edit screen. So can’t add javascript.

2)     If extend class and override “save” button, SFDC finds the empty fields first, and I never get called.

 

Second thought: Add a button to generate data, insert data into DOM so that it is there for the save. Problems:

1)     Still can’t modify screen.

2)     Even if I could add button, if it uses Visualforce, it will fail due to Cross site scripting restrictions.

 

Third thought: Write a new page in Visualforce. There are several minor problems:

1)     How do I fill in the account text box? $Component doesn’t seem to work.

2)     How do I set the date to be 90 days in the future for the calendar pulldown?

3)     How do I get the default calendar date into its text box right at the start?

But the major problem with #3 is that I can’t get the data saved! I’ve tried:

1)     this.save – that was fun when my extension function was save: endless loop. When I renamed my function, it said “I see no save here”.

2)     super.save – oh, right, this isn’t java.

3)     Save controller (which is passed in to initializer) as private variable "co" in the initializer, call co.save() in my save function.

4)     Upsert co.getRecords() in my save function.

 

I suppose if I knew SF better, this would be easy, but so far, it just ain’t happenin’, and any help would be appreciated.

MikeGinouMikeGinou

Can you transfer the logic required to generate the serial number to a trigger? Or is it too complex, or for code reuse reasons needs to remain in Javascript?

dclaardclaar

I think that it is possible to put the logic into the controller, but I'd basically have to rewrite bignum support, and I'm not eager to do that!

 

I currently have it set up so that button 1 generates the serial number, button 2 encodes it and saves it.

Problem is, I have to:

1) generate the serial number: A controller action, create a record in the serial number DB

2) Then I have to create a code based on the serial number, which is written in javascript.

3) Finally, I have to save that code, another controller action.

 

I tried to have button 1 do the controller action, and then onComplete="generate code and call controller", but that causes SF to do an AJAX call, and--for some reason I don't understand--the serial number doesn't make it back from the controller. It gets generated, but not returned. I would have thought that re-rendering would grab the new value from the record, and the examples seem to suggest that it does, but that's not what I'm seeing.