SAP HR Provisioning Modify Rule - Unable to Create a New Entry

Hello everyone,

I am currently facing an issue with an SAP HR Modifying Rule. Specifically, I am encountering this error when trying to create a new entry on SAP HR for any provisioned attribute.

image

While the rule works as expected for sync operations when the entry already exists on SAP HR, it fails when creating a new entry becomes necessary. Below is the relevant code snippet related to this operation:

private void modifyCommunicationData( String userId, String parValue, String type, String begDate, String endDate ) throws ConnectorException 
{
    JCoFunction jcoFunctionObject;
    if (null == begDate) 
    { 
        //If date is not present then use BAPI_EMPLCOMM_CREATE to add data
        
        SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd");
        Calendar begDateCalendar = Calendar.getInstance();
        Date begDate = begDateCalendar.getTime();
        String begDate = formatter.format(begDateCalendar.getTime());

        /*
        SimpleDateFormat formatter = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
        Date currentDate = new Date();
        String begDate = formatter.format(currentDate);
         */

        log.error("SAP HR Modifying Rule --- PUSHING BEGIN : " + begDate);

        jcoFunctionObject = connector.getFunction(destination,"BAPI_EMPLCOMM_CREATE");
    }
    else if (begDate.length() > 1 ) 
    { 
        //If date is alreday present then use BAPI_EMPLCOMM_CHANGE to modify data
        jcoFunctionObject = connector.getFunction(destination,"BAPI_EMPLCOMM_CHANGE");
    } 
    

    // BAPI locks the record for processing
    JCoFunction functionEnqueue = destination.getRepository().getFunction("BAPI_EMPLOYEE_ENQUEUE");
    functionEnqueue.getImportParameterList().setValue("NUMBER", userId);
    if ( functionEnqueue == null )
        throw new RuntimeException("BAPI_EMPLOYEE_ENQUEUE not found in SAP.");

    // BAPI to modify Communication data - email and phone
    if ( jcoFunctionObject == null )
        throw new RuntimeException("BAPI_EMPLCOMM_CHANGE not found in SAP.");

    String returnPersonnelID = null;
    jcoFunctionObject.getImportParameterList().setValue("EMPLOYEENUMBER", userId); // Personal Number
    jcoFunctionObject.getImportParameterList().setValue("SUBTYPE", type); // SubType 0010/0020 - Email/Phone
    jcoFunctionObject.getImportParameterList().setValue("VALIDITYBEGIN", begDate); // Begin Date
    jcoFunctionObject.getImportParameterList().setValue("VALIDITYEND", endDate); // End Date
    jcoFunctionObject.getImportParameterList().setValue("COMMUNICATIONID", parValue); // Email Address to modify

    // BAPI unlocks the record after processing
    JCoFunction functionDequeue = destination.getRepository().getFunction("BAPI_EMPLOYEE_DEQUEUE");
    functionDequeue.getImportParameterList().setValue("NUMBER", userId);
    if ( functionDequeue == null )
        throw new RuntimeException("BAPI_EMPLOYEE_DEQUEUE not found in SAP.");

    try 
    {
      // executing Bapis
        JCoContext.begin(destination);
        functionEnqueue.execute(destination);
        jcoFunctionObject.execute(destination);
        functionDequeue.execute(destination);
    } 
    catch (ConnectorException e) {
        throw e;
    } 
    finally {
        JCoContext.end(destination);
    }
}

I would highly appreciate any assistance or insights you can provide at your earliest convenience.

Thank you in advance!

Respectfully,

Hi @Augjm,

After reviewing the error, it seems like you’re setting the VALIDITYBEGIN as such:
jcoFunctionObject.getImportParameterList().setValue("VALIDITYBEGIN", begDate);

Is it possible begDate is a String type, not a DATE type?

Try the following snippet of code:

// Convert begDate String to JCoDataType.DATE
JCoDataType dataTypeDate = JCoDataType.DATE;
JCoFieldDate begDateField = dataTypeDate.createField("VALIDITYBEGIN", begDate);
jcoFunctionObject.getImportParameterList().setField(begDateField);

If this snippet doesn’t work, I would highly suggest printing the datatype for begDate as a starting point.

Hope this helps!