- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 08:39 AM
Hello Gurus,
I thought it was simple but have scratched enough hair that I font have to got barber anytime soon 🙂 !
This is how my form looks [sorry I'm unable to provide the real form screenshot shot]
As you can see I have used a 'relationship' table so that I can populate the related-list. Here is how the relationship is:
I wrote this script [I know its not right]. How do I create a script that inserts record into child [workpackages ] and creates insert a parent record and create a link between them?
//insert into workpackage first. This will create a related list record
var wp = new GlideRecord("u_commmercial_workpackage");
//wp.initialize();
wp.u_workpackage_description = 'test workpackage description';
var wp_sys_id = wp.insert();
//This should create the parent record
var nr = new GlideRecord('u_newrole');
nru_mali_number = 'Some Mali Number'; //I'm just putting this so the record doesnt look blank
var refRole_sys_id = nr.insert();
//This should bind the relationship
var relation = new GlideRecord('u_rel_role_workpackages');
relation.setValue(u_refrole,refRole_sys_id);
relation.setValue(u_workpackages, wp_sys_id);
relation.insert();
This script throws an error "u_refrole" is not defined. this is one of the fields I defined on the 'u_rel_role_workpackages' table of type reference and referencing u_newrole as above.
So, how do I create a script that inserts these two records [parent and child] and then creates relationship among them. I'm not too fussed which is created first.
Happy to provide more details if you want.
Thanks for reading!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 08:43 AM
in lines 14 and 15 you need to have the script like this :
relation.setValue('u_refrole',refRole_sys_id);
relation.setValue('u_workpackages', wp_sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 08:43 AM
in lines 14 and 15 you need to have the script like this :
relation.setValue('u_refrole',refRole_sys_id);
relation.setValue('u_workpackages', wp_sys_id);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 08:49 AM
Sometimes life feels like $h!t when I make those school boy errors!!
Thanks mate, it was very useful!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-23-2017 08:51 AM
Here is the updated code if anyone ends up like me:
var wp = new GlideRecord("u_commmercial_workpackage");
//wp.initialize();
wp.u_workpackage_description = 'test workpackage description';
var wp_sys_id = wp.insert();
var nr = new GlideRecord('u_newrole');
nr.u_mali_number = 'Some Mali Number'; //I'm just putting this so the record doesnt look blank
var refRole_sys_id = nr.insert();
var relation = new GlideRecord('u_rel_role_workpackages');
relation.setValue('u_refrole',refRole_sys_id);
relation.setValue('u_workpackages', wp_sys_id);
relation.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-23-2018 11:59 AM
I created a record producer for the Announcement table and I want to script it to automatically have a specific Service Portal listed in the Service Portal embedded list on the announcement form when submitted.
Would this method work? I am not sure how to script it.