Fusion Manage Forum
Welcome to Autodesk’s Fusion Manage (formerly Fusion 360 Manage) Forum. Share your knowledge, ask questions, and explore popular Fusion Manage topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

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

14 REPLIES 14
SOLVED
Reply
Message 1 of 15
PLM-Sylvain.Bailly
1314 Views, 14 Replies

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

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

14 REPLIES 14
Message 2 of 15

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.

 

 

Message 3 of 15

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

Message 4 of 15

You can add them as additionalOwner.

Martin Gasevski | Fusion 360 Team Product Manager
Message 5 of 15

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?

Message 6 of 15

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

Message 7 of 15

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]);
Message 8 of 15

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

Message 9 of 15

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 | Fusion 360 Team Product Manager
Message 10 of 15
Stuart_Gray
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

Message 11 of 15

Yeap no problem, I try on my side.

Message 12 of 15
Stuart_Gray
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

 

Message 13 of 15
gasevsm
in reply to: Stuart_Gray

Nice~!

Martin Gasevski | Fusion 360 Team Product Manager
Message 14 of 15

😉

Martin Gasevski | Fusion 360 Team Product Manager
Message 15 of 15

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 🙂

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report