有什么方法可以在请求中添加带有联系人的客户?

时间:2019-05-10 18:27:25

标签: netsuite php-toolkit

我正在使用PHPToolkit 2012,它必须与Netsuite建立联系的销售线索(客户)。我的代码可以正常工作,但有时会出现错误,因为我的帐户没有许可证,并且一次无法处理2个请求。

我正在尝试在请求中使用“联系人”创建客户。有可能吗?。

我比较XML文件并尝试了许多不同的方法,但是没有运气。

这是我现有的代码(有时会给我错误2无法同时处理2个请求)

$service = new NetSuiteService();

    $customer = new Customer();

    $customer->lastName = $lead_fname;
    $customer->firstName = $lead_lname;
    $customer->companyName = $lead_company_name;
    $customer->phone = $lead_phone;
    $customer->email = $lead_email;

    $customer->isPerson = false;
    $customer->globalSubscriptionStatus = '_softOptIn';

// Add Lead Status
    $leadStatus = new RecordRef();
    $leadStatus->internalId = '7';
    $leadStatus->name = 'LEAD-New';
    $customer->entityStatus = $leadStatus;

// Add Subsidiary
    $subsidiary = new RecordRef();
    $subsidiary->internalId = '1';
    $subsidiary->name = 'COMPANY NAME';
    $customer->subsidiary = $subsidiary;

// Add salesRep
    $salesRep = new RecordRef();
    $salesRep->internalId = $lead_sales_rep['internal_id'];
    $salesRep->name = $lead_sales_rep['name'];
    $customer->salesRep = $salesRep;

// Add Script ID = Direct Channel
    $directChannel = new SelectCustomFieldRef();
    $directChannel->scriptId = 'custentity_cseg1';
    $directChannel->internalId = '2121';

    $directChannel->value = new ListOrRecordRef();
    $directChannel->value->internalId = '1';
    $directChannel->value->name = 'Direct Sales';
    $directChannel->value->typeId = '301';

// Add Script ID = LEAD Source
    $leadSource = new SelectCustomFieldRef();
    $leadSource->scriptId = 'custentity4';
    $leadSource->internalId = '2192';

    $leadSource->value = new ListOrRecordRef();
    $leadSource->value->internalId = find_lead_source($lead_source);
    $leadSource->value->name = $lead_source;
    $leadSource->value->typeId = '318';

// Add Script ID = KEYBOARD
    $keyboard = new StringCustomFieldRef();
    $keyboard->scriptId = 'custentity_leadkeyword';
    $keyboard->internalId = '2191';
    $keyboard->value = $lead_keyboard;

// Add Script ID = LEAD Description
    $leadDescription = new StringCustomFieldRef();
    $leadDescription->scriptId = 'custentity_fs_descr_details';
    $leadDescription->internalId = '2186';
    $leadDescription->value = $lead_description;

// Add Script ID = Campaign
    $campaign = new StringCustomFieldRef();
    $campaign->scriptId = 'custentity_leadcampaign';
    $campaign->internalId = '2190';
    $campaign->value = $lead_campaign;

// Add Script ID = Marketting Source
    $source = new StringCustomFieldRef();
    $source->scriptId = 'custentity_leadmsource';
    $source->internalId = '2188';
    $source->value = $lead_marketing_source;

// Add Script ID = Medium
    $medium = new StringCustomFieldRef();
    $medium->scriptId = 'custentity_leadmedium';
    $medium->internalId = '2189';
    $medium->value = $lead_medium;

// Add Script ID = $Page From
    $pageFrom = new StringCustomFieldRef();
    $pageFrom->scriptId = 'custentity_pagefrom';
    $pageFrom->internalId = '2193';
    $pageFrom->value = $lead_page_from;


    $customFieldList = new customFieldList();
    $customFieldList->customField = array(
        $directChannel,
        $leadSource,
        $keyboard,
        $campaign,
        $source,
        $medium,
        $pageFrom,
        $leadDescription
    );

    $customer->customFieldList = $customFieldList;

    $request = new AddRequest();
    $request->record = $customer;

    $addResponse1 = $service->add($request);

    $contact = new Contact();
    $contact->entityId = $lead_fname . ' ' . $lead_lname;
    $contact->company = new RecordRef();
    $contact->company->internalId = $addResponse1->writeResponse->baseRef->internalId;
    $contact->email = $lead_email;
    $contact->phone = $lead_phone;

    $contact->subsidiary = $subsidiary;

    $request = new AddRequest();
    $request->record = $contact;

    $addResponse = $service->add($request);

    error_log(' add response into Netsuite ');
    error_log(print_r($addResponse, true));
    if (!$addResponse1->writeResponse->status->isSuccess) {
        return "ADD ERROR";
    } 
        return $addResponse1->writeResponse->baseRef->internalId;
    }

0 个答案:

没有答案