Genesys CTI User Forum
Genesys CTI User Forum => Genesys-related Development => Topic started by: nikhiltrivedi84 on February 19, 2016, 07:28:18 PM
-
Does anyone have a sample code to update Transaction Data in CME using crgTransaction? Any other method is also fine.
-
Hi,
I am not really a developer, so my code may be out of the usual standards... anyway find in the link below an example on how to get the CfgTransaction objects from Configuration Server.
http://owncloud.sujdik.com.br/index.php/s/NY0ZfphDmVSDWOH
To change a Transaction is simple... just retrieve it from the configuration server, make the changes to the CfgTransaction object as you wish and call the method save().
I also added a piece of code showing how to subscribe to Configuration Server notifications for when objects of an specific type change - a thing that I find very difficult due to not being a programmer.
Hope this helps
-
Below is my transaction update code with xml.
public boolean updateAnnexOption(String pSection, String pOption, String pValue)
{
Document confObject = null ;
String xml = null ;
boolean retval = true ;
logger.info("Starts...." + pSection + "," + pOption + "," + pValue) ;
try {
xml = "<ConfData>" +
"<CfgDeltaTransaction>" +
"<CfgTransaction>" +
"<DBID value='" + mTransactionDBID + "'/>" +
"</CfgTransaction>" +
"<changedUserProperties>" +
"<list_pair key='" + pSection + "'>" +
"<str_pair key='" + pOption + "' value='" + pValue +"'/>" +
"</list_pair>" +
"</changedUserProperties>" +
"</CfgDeltaTransaction>" +
"</ConfData>";
logger.info("Update annex option...." + xml) ;
confObject = DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new InputSource(new StringReader(xml))) ;
retval = updateObjects(CfgObjectType.CFGTransaction , confObject, null ) ;
} catch (Exception ex) {
logger.warning(CtiLogger.logstr("Exception....",ex)) ;
retval = false ;
}
return retval ;
}
boolean updateObjects(GEnum pObjectType, Document pConfObject, KeyValueCollection pFilter)
{
RequestUpdateObject message ; // Configuration Server에 변경을 요청 객체
Message response ; // Configuration Server에 변경을 결과 응답 메시지
boolean retval = true ;
//TreeMap retMap = new TreeMap() ; // Return 값 저장 변수
logger.info("Starts...." + pObjectType + "," + pConfObject + "," + pFilter) ;
try
{
// Configuration Server가 연결이 될 때까지 기다린다.
if( mConfServerProtocol.getState().equals(ChannelState.Opened))
{
// request message를 만든다
message = RequestUpdateObject.create(new Integer(pObjectType.ordinal()), pConfObject , pFilter);
logger.info("RequestUpdateObject....\n"+message) ;
// 정보 조회를 요청한다
response = mConfServerProtocol.request(message) ;
// 결과값이 왔는지 확인한다
if( response == null || !(response instanceof EventObjectUpdated) )
{
// 결과값이 없거나 object를 읽었다는 Event가 아니면
if( response == null )
{
logger.info("RequestUpdateObject response - no object updated....") ;
} else
{
logger.info("RequestUpdateObject response - no object updated....\n" + decode(response.toString()) ) ;
switch(response.messageId())
{
case EventError.ID :
EventError eventError = (EventError)response ;
if ( eventError.getErrorCode() == 29 )
{
mReadOnlyMode = true ;
logger.warning("Configuration server working mode is changed to Read-Only Mode....") ;
}
break ;
default:
break ;
}
}
retval = false ;
} else
{
retval = true ;
logger.info("RequestReadObjects response - object updated....\n" + decode(response.toString()) ) ;
}
} else
{
retval = false ;
logger.info("RequestUpdateObject response - no object updated because cfg server is not connected....") ;
}
} catch (Exception ex)
{
logger.warning(CtiLogger.logstr("Exception....",ex)) ;
retval = false ;
}
return retval;
}
-
I have updated the code that I have posted before, that includes changing a Transaction's Annex specified option inside a specified section, done directly on the objects by using the ConfService. At least to me (not a real developer) it is easier than using the low-level functions and xml with delta objects as our friend JungGiCho posted.
Also, one must be careful while using Delta Objects on a RequestUpdateObject, because if you send an option with the same value that already exists, it actually deletes the option instead of updating it to the same value.