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
ChristineVWChristineVW 

Can an s-control do this?

Do I need apex to do this, or can an s-control accomplish it? 

I have an object called Books, to which Pages are related.  I would like to create a button on the Pages related list so that, on any Book record, I can click the button and automatically generate multiple new Pages. 

Ideally I would like to have the number and type of Pages that are created depend upon the Book's record type and so forth.  For now, though, I just want to figure out how to be able to create a button that generates 10 new Pages records related to the Book. 

Thanks in advance. 
Execute EZSAASExecute EZSAAS
Yes, you can.  AJAX api for S-controls provides create() call for this purpose, you can use it to create new custom objects of "Page".
Then, create a list button on custom object "Page" using this S-control, and add it to "Book" page layout.
ChristineVWChristineVW
Could someone walk through this step-by-step?  I am looking at the Ajax toolkit developer's guide but am not sure exactly what needs to go where. 

I've tried ceating a custom button that executes an onclick javascript, but I don't think that's right.  I think I need to create an s-control of type html and then create a button of type s-control that utilizes it, but how do I use the ajax toolkit in the s-control? 

Would the s-control that the button uses look something like this if I want to create 15 Pages records? All this does when I push the button is open a blank window.

html tag, head tag

<script src="/soap/ajax/10.0/connection.js" type="text/javascript"></script>
<script>
var pages = [];
for (var i=0; i<15; i++)
{ var page = new sforce.SObject("Page__c");
pages.push(page); }
var result = sforce.connection.create(pages);
</script>

close head tag, close html tag

Message Edited by ChristineVW on 10-08-2007 01:05 PM

DevAngelDevAngel
Hi Christine,

That looks right to me.  You would probably want to refresh the page or something after the create was complete.
ChristineVWChristineVW
Actually it did work.  There is nothing in my code to associate the 15 new pages with the book, so it wasn't immediately apparent that 15 blank new page records had been created!

Being new to this I know what I need to do next but I don't know how to build it into my little s-control.  I need to: 

1)Give each of the 15 pages that gets created a distinct Type (there is a Type picklist on the Page object that contains 15 values);
2)Associate each of the 15 pages with the Book;
3)Similar to #1, give each of the 15 pages Statuses (another picklist on Page object) and Actual Dates (a date field on the Page object).

If I could get some advice on how to make 1 and 2 work I can go from there to fit the rest of the logic in.  Thanks all

p.s. Is there some good documentation out there other than the AJAX toolkit developer's guide or maybe just a bunch of sample s-controls in one place? 

DevAngelDevAngel
Hi again Christine,

If each of the pages need a distinct type, and since you are already in an indexed interation, you can create an array that contains each of the types and assign the type after creating the new page.

Code:
var types = [];
types[0] = "First Page";
types[1] = "Second Page";
//and so on

for (var i=0;i<15;i++) {
   var page = new sforce.SObject("Page__c");
   page.Type__c = types[i];
}
For number 2, you will need to set the field that contains the parent book id (Book__c maybe) to the id of the parent book.  The following line should work assuming the relationship field name is correct.

page.Book__c = "{!Book__c.Id}";

For number 3a, I assume all the pages will have the same status (since they are all new).

page.Status__c = "Unedited";

For number 3b you can simply set the date value.

page.ActualDate__c = new Date();


Hope this helps.




ChristineVWChristineVW
Thanks VERY much for your help, I've got it working now. 

Christine