1) Read the configuration file
2) Initialize the session
3) Verify the user we are connecting
4) Change AR Server connection queue
5) Set a flag (Radio button field) on a Remedy form
6) If there is an error while setting the flag, write the error message to another field.
Below is the code we have generated. You can actually change the parameters in blue color with yours.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "area.h"
#include "ar.h"
#include "arerrno.h"
#include "arextern.h"
#include "arstruct.h"
#include "ars_utils.h"
char ErrMsgStatus[2048];
void LogArsStatus(ARStatusList *);
int main(int argc, char * argv[])
{
ARNameType FormName;
ARStatusList arStatus;
ARControlStruct control;
char ProcessName [10];
AREntryIdType entryIdArr[1];
AREntryIdList entryIdL;
ARFieldValueList fieldL;
ARFieldValueStruct process;
ARFieldValueStruct error[2];
char ErrMsg [500];
char ConfigFile [128];
char requestID[16];
strcpy(requestID, argv[1]);
strcpy (ProcessName, "<PROCESS_NAME>");
strcpy(FormName, "<FORM_NAME>");
/*--------------------------------------------------------------------*/
/* Setup configuration file and control structure.
/*--------------------------------------------------------------------*/
strcpy(ConfigFile, "<CONFIG_FILE>");
if ((ConfigInit (ConfigFile)) != OKAY)
{
sprintf(ErrMsg, "Fatal error initialising config file\n");
ERROR (ERR_FATAL, ProcessName, ErrMsg, 0);
exit (1);
}
SetupControl (&control);
/*--------------------------------------------------------------------*/
/* Initialise Remedy ARS session
/*--------------------------------------------------------------------*/
if (ARInitialization(&control, &arStatus) >= AR_RETURN_ERROR)
{
sprintf(ErrMsg, "Fatal error - initialising ARS session");
ERROR (ERR_FATAL, ProcessName, ErrMsg, 0);
LogArsStatus (&arStatus);
FreeARStatusList(&arStatus, FALSE);
return;
}
FreeARStatusList(&arStatus, FALSE);
sprintf(ErrMsg, "Initialized ARS session");
ERROR (ERR_INFO, ProcessName, ErrMsg, 0);
/*--------------------------------------------------------------------*/
/* Verify the user we are running this process with
/*--------------------------------------------------------------------*/
if (ARVerifyUser(&control, NULL, NULL, NULL, &arStatus) >= AR_RETURN_ERROR)
{
sprintf (ErrMsg, "Fatal error - verifying user '%s' on server '%s'", control.user, control.server);
ERROR (ERR_FATAL, ProcessName, ErrMsg, 0);
LogArsStatus (&arStatus);
FreeARStatusList(&arStatus, FALSE);
return;
}
FreeARStatusList(&arStatus, FALSE);
sprintf(ErrMsg, "Verified user '%s'", control.user);
ERROR (ERR_INFO, ProcessName, ErrMsg, 0);
/*--------------------------------------------------------------------*/
/* Chnage the AR Server Connection Queue
/*--------------------------------------------------------------------*/
if (ARSetServerPort(&control, control.server, <SERVER_PORT>, <QUEUE_NUMBER>, &arStatus) >= AR_RETURN_ERROR)
{
sprintf (ErrMsg, "Fatal error - changing the queue for user '%s' on server '%s'", control.user, control.server);
ERROR (ERR_FATAL, ProcessName, ErrMsg, 0);
LogArsStatus (&arStatus);
FreeARStatusList(&arStatus, FALSE);
return;
}
FreeARStatusList(&arStatus, FALSE);
sprintf(ErrMsg, "Queue is changed");
ERROR (ERR_INFO, ProcessName, ErrMsg, 0);
/*--------------------------------------------------------------------*/
/* Set Flag
/*--------------------------------------------------------------------*/
entryIdL.numItems = 1;
entryIdL.entryIdList = entryIdArr;
strcpy(entryIdArr[0] , requestID);
fieldL.numItems = 1;
fieldL.fieldValueList = &process;
process.fieldId = atol("<FLAG_FIELD_ID>");
process.value.u.intVal = 0;
process.value.dataType = AR_DATA_TYPE_INTEGER; /*AR_DATA_TYPE_ENUM*/
if (ARSetEntry(&control, FormName, &entryIdL, &fieldL, 0, 1, &arStatus) >= AR_RETURN_ERROR)
{
sprintf(ErrMsg, "Fatal error at processing the transaction '%s'.", requestID);
ERROR (ERR_WARN, ProcessName, ErrMsg, 0);
LogArsStatus (&arStatus);
FreeARStatusList(&arStatus, FALSE);
fieldL.numItems = 2;
fieldL.fieldValueList = error;
error[0].fieldId = atol("<ERROR_MESSAGE_FIELD_ID>");
error[0].value.u.charVal = ErrMsgStatus;
error[0].value.dataType = AR_DATA_TYPE_CHAR;
if (ARSetEntry(&control, FormName, &entryIdL, &fieldL, 0, 1, &arStatus) >= AR_RETURN_ERROR)
{
sprintf(ErrMsg, "Fatal error at writing Error Msg to the request '%s'.", requestID);
ERROR (ERR_WARN, ProcessName, ErrMsg, 0);
LogArsStatus (&arStatus);
FreeARStatusList(&arStatus, FALSE);
}
exit(1);
}
return 1;
}
void LogArsStatus(ARStatusList *Status)
{
static char *MsgType;
ARStatusStruct *tempPtr;
int i;
sprintf(ErrMsgStatus, "ARS Status List: %u items", Status->numItems);
if (Status->numItems != 0)
{
tempPtr = Status->statusList;
for (i = 0; i < (int)Status -> numItems; i++)
{
switch(tempPtr->messageType)
{
case AR_RETURN_OK: MsgType = "NOTE "; break;
case AR_RETURN_WARNING: MsgType = "WARNING"; break;
case AR_RETURN_ERROR: MsgType = "ERROR "; break;
default: MsgType = "????? "; break;
}
sprintf(ErrMsgStatus, "%s\n Type: %s Message number: %d\n",
ErrMsgStatus, MsgType, tempPtr->messageNum);
if (tempPtr->messageText == NULL)
{
sprintf(ErrMsgStatus, "%s Message:\n", ErrMsgStatus);
}
else
{
sprintf(ErrMsgStatus, "%s Message: %s", ErrMsgStatus, tempPtr->messageText);
}
tempPtr++;
}
}
}
By Zekeriya Dinçer