Library initialization

It's highly important to call COSA.Core.Init() before making any service call!

Sample code

Currently implemented messages

Delete message

Request signature

function Delete ( /*string*/ logicalName, /*string*/ id ) { /*...*/ }

Usage

function btnTestButton_click() {
	var deleteRequest_0 = new COSA.Request.Delete('contact', '907a55b2-560b-e511-942c-005056b8429a');
	COSA.Core.Execute(deleteRequest_0, contact_deleted);
}

function contact_deleted( responseObj ) {
	//(responseObj instanceof COSA.Error == true) in case of any error generated by SOAP service endpoint
	//(responseObj instanceof COSA.Response.Delete == true) if case of successful execution
}
Back to Contents

Update message

Request signature

function Update ( /*COSA.BusinessEntity*/ entity ) { /*...*/ }

Usage

function btnTest_clicked() {
	var contact_0 = new COSA.BusinessEntity('contact', 'B70BC872-6308-E511-942C-005056B8429A');
	contact_0.attributes.emailaddress51 = '#00584@somemail.com';
	contact_0.attributes.preferredcontactmethodcode = null;
	var updateRequest_0 = new COSA.Request.Update(contact_0);
	COSA.Core.Execute(updateRequest_0, contact_updated);
}

function contact_updated ( responseObj ) {
}
Back to Contents

Create Message

Request signature

//Request
function Create ( /*COSA.BusinessEntity*/ entity ) { /*...*/ }

//Response
function Create () {
    this.id = null;
}

Usage

function createContact () {
    var name = '#'.concat(new Date().getMilliseconds()),
        contact_0 = new COSA.BusinessEntity('contact', null, {
            lastname: name,
            emailaddress1: name.concat('@mail.com'),
            creditlimit: new COSA.Money(100.50),
            numberofchildren: new COSA.XrmValue(2, COSA.Const.AttributeType.WholeNumber),
            creditonhold: new COSA.XrmValue(true, COSA.Const.AttributeType.Boolean),
            parentcustomerid: new COSA.EntityReference('account', 'D54A1A4A-A9FF-E411-942C-005056B8429A'),
            gendercode: new COSA.OptionSetValue(1),
            birthdate: new Date(),
            address1_latitude: new COSA.XrmValue(14.55, COSA.Const.AttributeType.FloatingPointNumber)
        });
    var createRequest_0 = new COSA.Request.Create(contact_0);

    COSA.Core.Execute(createRequest_0, contact_created);
}

function contact_created ( response ) {
    if ( response instanceof COSA.Response.Create ) {
        console.log('id: '.concat(response.id));
    }
}

Usage #2

function createEmail () {
    var msc = new Date().getMilliseconds(),
        email_0 = new COSA.BusinessEntity('email', null, {
        from: new COSA.EntityCollection([
            new COSA.ActivityParty(new COSA.EntityReference('systemuser', '90CD37D5-5AEE-E411-9428-005056B8429A'))
        ]),
        to: new COSA.EntityCollection([
            new COSA.ActivityParty(new COSA.EntityReference('contact', '9cccfe19-eb14-e511-942f-005056b8429a')),
            new COSA.ActivityParty(new COSA.EntityReference('contact', '06426223-eb14-e511-942f-005056b8429a'))
        ]),
        subject: 'Attention required!'.concat(' [', msc, ']')
    });

    var createRequest_0 = new COSA.Request.Create(email_0);
    COSA.Core.Execute(createRequest_0, email_created);
}

function email_created ( response ) {
    if ( response instanceof COSA.Response.Create ) {
        console.log('email id: '.concat(response.id));
    } else {
        console.log(response.faultstring);
    }
}
Back to Contents

Retrieve message

Request signature

//Request
function Retrieve ( /*string*/ logicalName, /*string*/ id, /*COSA.ColumnSet*/ columnSet ) { /*...*/ }

//Response
function Retrieve () {
    this.businessEntity = null; /* instanceof COSA.BusinessEntity */
}

Usage

function retrieveContact () {
    var retrieveRequest_0 = new COSA.Request.Retrieve('contact', '386df320-f114-e511-942f-005056b8429a', new COSA.ColumnSet([]));
	var retrieveRequest_1 = new COSA.Request.Retrieve('contact', '386df320-f114-e511-942f-005056b8429a', new COSA.ColumnSet(['parentcustomerid', 'birthdate']));

    COSA.Core.Execute(retrieveRequest_0, contact_retrieved);
    COSA.Core.Execute(retrieveRequest_1, contact_retrieved);
 }

function contact_retrieved ( response ) {
    if ( response instanceof COSA.Response.Retrieve ) {
        debugger;
    }
}
Back to Contents

RetrieveMultiple message

Request signature

//Request
function RetrieveMultiple ( /*COSA.QueryExpression*/ queryExpression ) { /*...*/ }

//Response
function RetrieveMultiple () {
	this.entityCollection = null;
}

Usage

function retrieveMultiple() {
    var linkEntity_0 = new COSA.LinkEntity({
        linkFromEntityName: 'contact',
        linkToEntityName: 'account',
        linkFromAttributeName: 'parentcustomerid',
        linkToAttributeName: 'accountid',
        joinOperator: COSA.Const.JoinOperator.Inner,
        columns: new COSA.ColumnSet(['name'])
    });

    var filterExpression_0 = new COSA.FilterExpression(COSA.Const.FilterOperator.AND);
    filterExpression_0.addCondition(new COSA.ConditionExpression('emailaddress1', COSA.Const.ConditionOperator.Like, '%@mail.com'));
    var queryExpression_0 = new COSA.QueryExpression('contact');
    queryExpression_0.criteria = filterExpression_0;
    queryExpression_0.columnSet =  new COSA.ColumnSet(['fullname', 'emailaddress1']);
    queryExpression_0.linkEntities.push(linkEntity_0);

    var retrieveMultipleRequest_0 = new COSA.Request.RetrieveMultiple(queryExpression_0);
    COSA.Core.Execute(retrieveMultipleRequest_0, retrieveMultipleRequest_callback)
}
Back to Contents

RetrieveEntity message

Signatures

//Request
function RetrieveEntity ( /*string*/ logicalName, /*string or COSA.Const.EntityFilters*/filters, /*boolean*/retrieveAsIfPublished) { /*...*/ }

//Response
function RetrieveEntity () {
	this.entityMetadata = null;
}

Usage

function retrieveEntity() {
    var retrieveEntity_0 = new COSA.Request.RetrieveEntity('contact', COSA.Const.EntityFilters.Attributes, true);

    COSA.Core.Execute(retrieveEntity_0, retrieveEntity_callback);
}

function retrieveEntity_callback ( response ) {
    if ( response instanceof COSA.Response.RetrieveEntity ) {
        console.log('retrieveEntity successful!')
    }
}
Back to Contents

RetrieveAttribute message

Signatures

//Request
function RetrieveAttribute ( /*string*/ entityLogicalName, /*string*/ logicalName, /*boolean*/ retrieveAsIfPublished ) { /*...*/ }

//Response
function RetrieveAttribute () {
	this.attributeMetadata = null;
}

Usage

function retrieveAttribute () {
    var retrieveAttributeRequest_0 = new COSA.Request.RetrieveAttribute('contact', 'address1_latitude', true);

    COSA.Core.Execute(retrieveAttributeRequest_0, attribute_retrieved);
}

function attribute_retrieved ( response ) {
    if ( response instanceof COSA.Response.RetrieveAttribute ) {
        console.log('RetrieveAttribute successful!');
    }
}
Back to Contents

RetrieveUserPrivileges message

Signatures

//Request
function RetrieveUserPrivileges ( /*string*/ userId ) { /*...*/ }

//Response
function RetrieveUserPrivileges () {
	this.rolePrivileges()
}

Usage

function retrieveUserPrivileges () {
    var retrieveUserPrivilegesRequest_0 = new COSA.Request.RetrieveUserPrivileges('A2BB25F1-F49A-E411-9418-005056B8429A');

    COSA.Core.Execute(retrieveUserPrivilegesRequest_0, privileges_retrieved);
}

function privileges_retrieved ( response ) {
    if ( response instanceof COSA.Response.RetrieveUserPrivileges ) {
        console.log('RetrieveUserPrivileges successful');
    }
}
Back to Contents

RetrievePrincipalAccess message

Signatures

//Request
function RetrievePrincipalAccess ( /*COSA.EntityReference*/ principal, /*COSA.EntityReference*/ target ) { /*...*/ }

//Response
function RetrievePrincipalAccess () {
	this.accessRights = null;
}

Usage

function retrievePrincipalAccess () {
    var retrievePrincipalAccessRequest_0 = new COSA.Request.RetrievePrincipalAccess(
        new COSA.EntityReference('systemuser', 'A2BB25F1-F49A-E411-9418-005056B8429A'),
        new COSA.EntityReference('contact', 'B70BC872-6308-E511-942C-005056B8429A')
    );

    COSA.Core.Execute(retrievePrincipalAccessRequest_0, retrievePrincipalAccess_callback);
}

function retrievePrincipalAccess_callback ( response ) {
    if ( response instanceof COSA.Response.RetrievePrincipalAccess ) {
        console.log('retrievePrincipalAccess successful!')
    }
}
Back to Contents

ExecuteMultiple message

Signatures

//Request
function ExecuteMultiple(/*COSA.OrganizationRequestCollection*/ organizationRequestCollection, /*COSA.ExecuteMultipleSettings*/ executeMultipleSettings)

//OrganizationRequestCollection
function OrganizationRequestCollection( /*Array*/ requests)

//ExecuteMultipleSettings
function ExecuteMultipleSettings (/*Boolean*/ continueOnError, /*Boolean*/ returnResponses)

//Response
function ExecuteMultiple () {
        this.responses = null;
        this.isFaulted = false;
        this.error = null;
    }

Usage

function executeMultiple () {
    var retrieveEntity_0 = new COSA.Request.RetrieveEntity('contact', COSA.Const.EntityFilters.Attributes, true);
    var retrievePrincipalAccessRequest_0 = new COSA.Request.RetrievePrincipalAccess(
        new COSA.EntityReference('systemuser', 'A2BB25F1-F49A-E411-9418-005056B8429A'),
        new COSA.EntityReference('contact', 'B70BC872-6308-E511-942C-005056B8429A')
    );

    var organizationRequestCollection_0 = new COSA.OrganizationRequestCollection([retrieveEntity_0, retrievePrincipalAccessRequest_0]);
    var executeMultipleRequest_0 = new COSA.Request.ExecuteMultiple(organizationRequestCollection_0, new COSA.ExecuteMultipleSettings(true, false));

    COSA.Core.Execute(executeMultipleRequest_0, executeMultiple_callback);
}

function executeMultiple_callback ( response ) {
    if ( response instanceof COSA.Response.ExecuteMultiple ) {
        console.log('ExecuteMultiple successful!');
    }
}
Back to Contents

Last edited Dec 29, 2015 at 8:04 AM by sciencesoft, version 9