• Resolved siddiquemahsud

    (@siddiquemahsud)


    I have a button on a page, and I needed to delete a CRM record by clicking this button. I have added the below code function.php file in child theme.

    function ajax_delete_record() {
    if ( ! isset( $_POST['entity'], $_POST['id'] ) ) {
    error_log( 'Missing parameters: ' . print_r( $_POST, true ) );
    wp_send_json_error( 'Invalid parameters' );
    return;
    }

    $entity = sanitize_text_field( $_POST['entity'] );
    $id = sanitize_text_field( $_POST['id'] );

    error_log( "Attempting to delete record: Entity = $entity, ID = $id" );

    try {
    // Perform deletion logic
    //$ref = new \AlexaCRM\CRMToolkit\Entity\EntityReference( $entity, $id );
    $request = [
    [
    'key' => 'id',
    'type' => 'string',
    'value' => $id,
    ]
    ];

    $response = ASDK()->executeAction( 'new_WPDeleteSessionAction', $request );
    if ( $response ) {
    wp_send_json_success( 'Record deleted successfully.' );
    } else {
    wp_send_json_error( 'Failed to delete record.' );
    }
    } catch ( Exception $e ) {
    error_log( 'Error: ' . $e->getMessage() );
    wp_send_json_error( 'Error: ' . $e->getMessage() );
    }
    }
    add_action( 'wp_ajax_delete_record', 'ajax_delete_record' );
    add_action( 'wp_ajax_nopriv_delete_record', 'ajax_delete_record' );

    It code returns error “HTTP error! status: 500” on following lines:
    $ref = new \AlexaCRM\CRMToolkit\Entity\EntityReference( $entity, $id );
    $response = ASDK()->executeAction( ‘new_WPDeleteSessionAction’, $request );

    I’ve also added below namespace, but not worked:
    use AlexaCRM\CRMToolkit\Entity\EntityReference;

    and the js code working fine, as I can get the logs back.

    Is there any namespaces are missing? Please help

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author alexacrm

    (@alexacrm)

    @siddiquemahsud

    why are you using a custom action to delete a record instead of delete method from the toolkit? But if you want to create an EntityReference, correct namespace is \AlexaCRM\Xrm:

    $ref = new \AlexaCRM\Xrem\EntityReference( $entity, $id);

    Thread Starter siddiquemahsud

    (@siddiquemahsud)

    Alexa Support, thank you so much for pointing me in the right direction. I have never used or needed to learn about the APIs toolkit before, so I appreciate your guidance.

    As I start exploring the APIs toolkit, I have a one question below:

    1. Since I already have the Dataverse plugins, is the toolkit included within the Dataverse plugin? Can I use it directly (within the child theme function.php), or do I need to install the toolkit separately on the wordpress hosting sever?

    Thanks

    Plugin Author alexacrm

    (@alexacrm)

    @siddiquemahsud toolkit is included as part of the plugin. We handle connection, logging, caching. You can use it directly using ConnectionService, for example:

    $webapi = ConnectionService::instance()->getClient();
    $webapi->RetrieveByReference(...);
Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Error while executing a CRM action’ is closed to new replies.