Fusion Lifecycle Forum
Welcome to Autodesk’s Fusion Lifecycle Forums. Share your knowledge, ask questions, and explore popular Fusion Lifecycle topics.
This page has been translated for your convenience with an automatic translation service. This is not an official translation and may contain errors and inaccurate translations. Autodesk does not warrant, either expressly or implied, the accuracy, reliability or completeness of the information translated by the machine translation service and will not be liable for damages or losses caused by the trust placed in the translation service. To translate this discussion, select the language.

Fusion Lifecycle Forum

Reply
Post 1 of 15
Accepted Solution

Change owner of the item created with the owner of the current item

275 Views, 14 Replies
02-01-2017 07:01 AM

Hello,

 

I have an item, when I finish its workflow, I have an action script which create another item in another workspace. The problem is that the last person who performs the action in the first workflow become the owner of the new item in the other worspace.

 

 

var newProperties = [];
            newProperties.TITLE = item.TITLE;
            var newItem = createNewItem('WS_NUMBERTWO', newProperties);
function createNewItem(baseItemName, newItemProperties){

	newItem = createItem(baseItemName);
	
	for(var propKey in newItemProperties){
		newItem[propKey] = newItemProperties[propKey];
	}
	
	return newItem;
}

 

SO, this code create the new item in the other WS. Now I try to change the owner outside the function "createNewItem".

 

I try to push the owner of the first item in the second one but I try lot of different scripts without success :

 

 

            ////////////////////////////////////
            /*var userName = item.master.owner; // get the owner name of the record
            //var userName = item.CONTENT_DEVELOPER_1[0];
            println(userName);
            
            if(userName !==null){
            
            var nameArray = userName.split(", ");
            var LName = nameArray[0];
            var FName = nameArray[1];
            var users = Security.searchUsers({lastName:LName, firstName:FName});
            
            newItem.master.owner = users[0];
            
            }
            
            newItem.master.owner = item.master.owner;
            
            
            newItem.master.owner = loadItem(item.id).master.owner;
            */
            var newOwnerUserId = item.master.owner.id;
            var newOwner = Security.loadUser('newOwnerUserId'); // load user with id 
            newItem.master.owner = newOwner;  // update owner
            
            ////////////////////////////////////

First, the "split" function is not reconized and I do not know how to add it. I dont know if it can fix the problem.

 

If you can help me.

Thanks,

Sylvain

Nailed it!

 

So you can't change the ownership of item B, using a script (script 1) that runs originally from item A.

 

You can however get script 2 (that runs in item B) to read back to item A to get the owner, and then write it to item B.

 

I used the on-create script for item B as script 2.

 

So,

 

Script 1 on item A:

 

 newProperties = [];
newProperties.NAME = "My Name";
newProperties.NUMBER_OF_DAYS_CARRYING_OVER = 4;
newProperties.LINK_TO_OLD_RECORD = item; // Link to item A in item B
var newItem = createNewItem('WS_HOLIDAY_REQUEST_FORM', newProperties);
item.LINK_TO_NEW_RECORD = newItem; // Link to item B in item A

Script 2 on item B (on create) :

if(item.LINK_TO_OLD_RECORD !== null) {
var dude = item.LINK_TO_OLD_RECORD.master.owner.id;
println(dude);
var newOwner = Security.searchUsers({id:dude});
item.master.owner = Security.loadUser(newOwner[0]);
}

 

Note: Both items are in the same workspace. Not tested how this works if moving between workspaces.

 

Hope this helps you!

 

Cheers

 

Post 2 of 15

Re: Change owner of the item created with the owner of the current item

02-01-2017 09:11 AM in reply to: sylvain.bailly

I'm not sure you can actually set the owner of the new object different from the person calling the script.

 

But your question about split is easier to answer.

 

item.master.owner is the user object and not a string.  So you can get the email or the id using item.master.owner.email or item.master.owner.loginName.

 

 

Post 3 of 15

Re: Change owner of the item created with the owner of the current item

02-01-2017 12:41 PM in reply to: tony.mandatori

Hi,

 

The person who performs the last action in the workflow is not the owner of the item (99% of the time). The action scriipt is in this last transition so, if I understand your question, the person is not the same.

For example:

- person A creates an item

- submits this item for approval

- person B accepts and an action script on this transition create another item is another workspace

- for the moment, person B is the owner of the new item and I would like to have person A as the owner of this new item

 

Do you see what I mean?

 

Cheers,

Sylvain

Post 4 of 15

Re: Change owner of the item created with the owner of the current item

02-01-2017 07:10 PM in reply to: sylvain.bailly
You can add them as additionalOwner.
--
Martin Gasevski | Product Manager | Autodesk Fusion Lifecycle
Post 5 of 15

Re: Change owner of the item created with the owner of the current item

02-02-2017 12:57 AM in reply to: gasevsm

Hi,

 

This is not the goal because in the workflow of the new item, ONLY the owner can perform transition according to a condition script.

It is not possible to do what I want?

Post 6 of 15

Re: Change owner of the item created with the owner of the current item

02-02-2017 01:54 AM in reply to: sylvain.bailly

I have this script that will change the item.owner, to whoever's name is selected in the item.NAME field, which is a linking picklist to our Employees workspace.

 

function changeOwnerTo (thisName) {

var randomVariable_1 = thisName.AUTODESK_ID.split(", ");
firstName = randomVariable_1[1];
lastName = randomVariable_1[0];
randomVariable_2 = Security.searchUsers({firstName:firstName,lastName:lastName});
item.master.owner = Security.loadUser(randomVariable_2[0]);
}

Could try this on the on-create script?

 

Cheers

Post 7 of 15

Re: Change owner of the item created with the owner of the current item

02-02-2017 03:25 AM in reply to: Stuart_Gray

Perhaps it can help but in my first item I have a field (a link to the second item created). In fact it is a pick list field where it takes an item of the second workspace.

And the same in my item created. I have a field where I have a link to the first item.


Is it possible, in the creation script of the second item to go to this field, take the owner of this item and use your code to replace the owner in the item created?

 

Something like it:

 

var upOwner = item.RELATED_DESIGN_REVIEW; //property which refers to the previous item
var newOwner = upOwner.master.owner; //HOW TO CATCH THE NAME to split it after in the next lines?
var randomVariable_1 = newOwner.AUTODESK_ID.split(", ");
firstName = randomVariable_1[1];
lastName = randomVariable_1[0];
randomVariable_2 = Security.searchUsers({firstName:firstName,lastName:lastName});
item.master.owner = Security.loadUser(randomVariable_2[0]);
Post 8 of 15

Re: Change owner of the item created with the owner of the current item

02-02-2017 04:40 AM in reply to: sylvain.bailly

Hmm, I see what you are saying.

 

In that case, it's unlikely you'll need most of that script. Let me try something on my lunch and I'll report back

Post 9 of 15

Re: Change owner of the item created with the owner of the current item

02-02-2017 05:43 AM in reply to: sylvain.bailly
Its possible to do all that via script to get the owner from the first item and add them as the additional owner of the newly spawned item.
--
Martin Gasevski | Product Manager | Autodesk Fusion Lifecycle
Post 10 of 15

Re: Change owner of the item created with the owner of the current item

02-02-2017 06:09 AM in reply to: gasevsm

Sorry mate I've been playing around and so far am unable to change the owner using another owner object.

 

 

Not sure why it isn't working, as the script I posted above works fine. I'll maybe take a look later once I'm done for the day.

 

Cheers

Post 11 of 15

Re: Change owner of the item created with the owner of the current item

02-02-2017 06:18 AM in reply to: Stuart_Gray

Yeap no problem, I try on my side.

Post 12 of 15

Re: Change owner of the item created with the owner of the current item

02-02-2017 06:38 AM in reply to: Stuart_Gray

Nailed it!

 

So you can't change the ownership of item B, using a script (script 1) that runs originally from item A.

 

You can however get script 2 (that runs in item B) to read back to item A to get the owner, and then write it to item B.

 

I used the on-create script for item B as script 2.

 

So,

 

Script 1 on item A:

 

                      newProperties = [];
                      newProperties.NAME = "My Name";
                      newProperties.NUMBER_OF_DAYS_CARRYING_OVER = 4;
                      newProperties.LINK_TO_OLD_RECORD = item; // Link to item A in item B
                      
                      var newItem = createNewItem('WS_HOLIDAY_REQUEST_FORM', newProperties);
                      
                      item.LINK_TO_NEW_RECORD = newItem; // Link to item B in item A

Script 2 on item B (on create) :

if(item.LINK_TO_OLD_RECORD !== null) { 
    var dude = item.LINK_TO_OLD_RECORD.master.owner.id;
    println(dude);
    var newOwner = Security.searchUsers({id:dude});
    item.master.owner = Security.loadUser(newOwner[0]);
}

 

Note: Both items are in the same workspace. Not tested how this works if moving between workspaces.

 

Hope this helps you!

 

Cheers

 

Post 13 of 15

Re: Change owner of the item created with the owner of the current item

02-02-2017 07:27 PM in reply to: Stuart_Gray
Nice~!
--
Martin Gasevski | Product Manager | Autodesk Fusion Lifecycle
Post 14 of 15

Re: Change owner of the item created with the owner of the current item

02-02-2017 07:53 PM in reply to: sylvain.bailly
;)
--
Martin Gasevski | Product Manager | Autodesk Fusion Lifecycle
Post 15 of 15

Re: Change owner of the item created with the owner of the current item

02-06-2017 01:05 AM in reply to: gasevsm

Hi,

 

Thank you very much both of you. It works perfectly.

Sorry for the delay but cannot test before. I m so happy on this Monday morning :)

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post


Couldn’t make it to Autodesk University? Some of the Fusion Lifecycle Classes are available to watch on-demand:
http://autode.sk/2gJmBy3