Author Topic: PSDK Update Object  (Read 8033 times)

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
PSDK Update Object
« on: October 05, 2017, 08:00:43 AM »
Hello,

I try to update a person but get the message that the object is already saved.
Actualy I want to move the person to a different folder.

Code:
var folder = func.folder_query("disabled", 3);
var person = func.person_query(textBox_username.Text);
person.SingleOrDefault().FolderId = folder.DBID;<-- here I get the error message tha tobject can#t be saved
person.SingleOrDefault().Refresh(); <-- Here I tried also save

Am I doing something wrong?

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: PSDK Update Object
« Reply #1 on: October 06, 2017, 06:04:01 PM »
I have noticed, when I update the email field then it’s working.
just the move to another folder is giving me the error.

Offline hsujdik

  • Hero Member
  • *****
  • Posts: 541
  • Karma: 30
Re: PSDK Update Object
« Reply #2 on: October 06, 2017, 06:16:35 PM »
[code]
person.SingleOrDefault().FolderId = folder.DBID;<-- here I get the error message tha tobject can#t be saved
[/code]

Maybe the user doesn't have permission on this folder. Can you check that? Also, what is the content of [b]folder.DBID[/b]? Check if it is not comming null...

[code]
person.SingleOrDefault().Refresh();
[/code]
This doesn't save the object. The correct method should be [b].Save()[/b]

Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: PSDK Update Object
« Reply #3 on: October 08, 2017, 11:29:43 AM »
Im Running this code in a Development Environment with the default user. Permission on folder is correct.

The folder.dbid is not null so that should also be fine.

And person.save() is also not working S the exception is thrown before the save.

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7639
  • Karma: 56330
Re: PSDK Update Object
« Reply #4 on: October 08, 2017, 03:50:05 PM »
Which exception? The message should tell you exactly what is wrong

Enviado de meu E6633 usando Tapatalk


Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: PSDK Update Object
« Reply #5 on: October 09, 2017, 07:44:31 AM »
This is the exception I get at the folderID.
{"Can't change this property because object has been saved."}

and I get this at this line:
person.SingleOrDefault().FolderId = folder.DBID;

folder.DBID is not null.

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7639
  • Karma: 56330
Re: PSDK Update Object
« Reply #6 on: October 09, 2017, 12:30:33 PM »
I think you need to use Set property

Enviado de meu E6633 usando Tapatalk


Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: PSDK Update Object
« Reply #7 on: October 09, 2017, 01:44:19 PM »
Hi cavagnaro,

can you explain what you mean by using set property?

Offline cavagnaro

  • Administrator
  • Hero Member
  • *****
  • Posts: 7639
  • Karma: 56330
Re: PSDK Update Object
« Reply #8 on: October 09, 2017, 02:50:15 PM »
You are doing a Query...not modifying the person object with CfgPerson object...


Check http://www.sggu.com/smf/index.php?topic=10649.0


Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: PSDK Update Object
« Reply #9 on: October 09, 2017, 03:37:14 PM »
I have changed my code to make it a bit more visible

            CfgPersonQuery pquery = new CfgPersonQuery(func.app_service);
            pquery.UserName = "testagent";
            ICollection<CfgPerson> person = pquery.Execute();
            person.SingleOrDefault().FolderId = 191;

At person.SingleOrDefault().FolderId = 191; I get the exception that object is already saved.
So I'm trying to change the Object unless I have to change a differnt object then CfgPerson.
But there I do not know where to start.

There is a table cfg_obj_folder with the info of the folder and the objects but I do not now how to update this with the PSDK.


Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: PSDK Update Object
« Reply #10 on: October 10, 2017, 08:14:49 AM »
I reviewed my code and checked it and tried some things and came across to this:

            CfgPersonQuery qPerson = new CfgPersonQuery();
            qPerson.UserName = "testagent";

            CfgPerson myPerson = func.app_service.RetrieveObject<CfgPerson>(qPerson);

            CfgObjectID obj = new CfgObjectID(func.app_service, myPerson);
           
            CfgFolderQuery q = new CfgFolderQuery(func.app_service);
            q.Name = "disabled";
            var res = q.Execute();
            res.SingleOrDefault().ObjectIDs = <== Here I have to get the ObjectID but which one?

I get this error message when tring to set the object ID

Severity Code Description Project File Line Column Category Suppression State
Error CS0029 Cannot implicitly convert type 'int' to 'System.Collections.Generic.ICollection<Genesyslab.Platform.ApplicationBlocks.ConfigurationObjectModel.CfgObjects.CfgObjectID>' GenesysTool C:\Users\Rene\Documents\Visual Studio 2015\Projects\GenesysTool\GenesysTool\Form_Disable_Users.cs 58 47 Compiler Active



Offline carpio

  • Newbie
  • *
  • Posts: 34
  • Karma: 0
Re: PSDK Update Object
« Reply #11 on: October 10, 2017, 08:37:41 AM »
For those who are interested, I have managed to move the person this is the code:

            CfgObjectID id = new CfgObjectID(func.app_service, null);
            id.DBID = person.SingleOrDefault().DBID;
            id.Type = CfgObjectType.CFGPerson;
            ICollection<CfgObjectID> obj_id = folder.ObjectIDs;
            obj_id.Add(id);
            folder.ObjectIDs =obj_id;
            folder.Save();

Offline PeteHoyle

  • Full Member
  • ***
  • Posts: 126
  • Karma: 13
Re: PSDK Update Object
« Reply #12 on: October 10, 2017, 08:55:28 AM »
It looks like you are trying to move a Person to another folder, below is an example of how to do that:

[code]            CfgFolderQuery qFolder = new CfgFolderQuery();
            qFolder.Name = "MyNewFolder";
            qFolder.Type = (Int32)CfgObjectType.CFGPerson;
            qFolder.OwnerDbid = 1;
            CfgFolder folder = confService.RetrieveObject<CfgFolder>(qFolder);


            CfgPersonQuery qPerson = new CfgPersonQuery();
            qPerson.UserName = "Trevor";
            CfgPerson person = confService.RetrieveObject<CfgPerson>(qPerson);

            CfgObjectID objectID = new CfgObjectID(confService, folder);
            objectID.DBID = person.DBID;
            objectID.Type = CfgObjectType.CFGPerson;

            ICollection<CfgObjectID> tempList = folder.ObjectIDs;
            tempList.Add(objectID);
            folder.ObjectIDs = tempList;
            folder.Save();[/code]

Offline benjamin

  • Newbie
  • *
  • Posts: 5
  • Karma: 0
Re: PSDK Update Object
« Reply #13 on: October 10, 2017, 03:25:29 PM »
Hi,
i have tried to adapt this code for move some places to specific folder.
I've retrieved the folderdbid and placedbid but last step for move object to destination folder doesn't work.

Can you help me?

[u][color=red][b]I have solved. Thank you[/b][/color][/u]
« Last Edit: October 10, 2017, 03:53:18 PM by benjamin »

Offline hsujdik

  • Hero Member
  • *****
  • Posts: 541
  • Karma: 30
Re: PSDK Update Object
« Reply #14 on: October 10, 2017, 03:53:09 PM »
[quote author=benjamin link=topic=10658.msg48466#msg48466 date=1507649129]
Hi,
i have tried to adapt this code for move some places to specific folder.
I've retrieved the folderdbid and placedbid but last step for move object to destination folder doesn't work.

Can you help me?
[/quote]

The folder must have the same objecttype as the object you want to move... confirm that the folder has the type of Place...