Genesys CTI User Forum
Genesys CTI User Forum => Genesys-related Development => Topic started by: carpio 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?
-
I have noticed, when I update the email field then it’s working.
just the move to another folder is giving me the error.
-
[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]
-
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.
-
Which exception? The message should tell you exactly what is wrong
Enviado de meu E6633 usando Tapatalk
-
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.
-
I think you need to use Set property
Enviado de meu E6633 usando Tapatalk
-
Hi cavagnaro,
can you explain what you mean by using set property?
-
You are doing a Query...not modifying the person object with CfgPerson object...
Check http://www.sggu.com/smf/index.php?topic=10649.0
-
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.
-
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
-
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();
-
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]
-
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]
-
[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...
-
Java method to move objects
/**
Move existing object to new folder
@param moveToFolder target folder Dbid
@param movedObjectDbId moved object dbid
@param movedObjectType moved object type
*/
private void moveToFolder(CfgFolder moveToFolder, int movedObjectDbId , CfgObjectType movedObjectType) {
CfgObjectID movedId = new CfgObjectID(confService, null);
movedId.setDBID( movedObjectDbId );
movedId.setType(movedObjectType);
Collection<CfgObjectID> moveToFolderObjectIDs = moveToFolder.getObjectIDs();
moveToFolderObjectIDs.add(movedId);
moveToFolder.setObjectIDs(moveToFolderObjectIDs);
try {
moveToFolder.save();
}
catch (Exception exc){
log.trace(String.format("Could not move object %s (dbid=%s) " +
"to folder %s (dbid=%s) due to the error: %s ",
movedObjectType, movedObjectDbId,
moveToFolder.getName(), moveToFolder.getDBID(), exc.getMessage() ),exc);
}
}