الخميس، 16 أبريل 2015

How to assign Equipment/Facility to existed resource group.


//********* Create New Equipment/Facility *******************************
        Entity Equipment = new Entity("equipment");
        Equipment["name"]="Test Equipment 1";
        Equipment["timezonecode"]=1;
        Equipment["businessunitid"] = new EntityReference("businessunit", new Guid("BusinessUnitId"));

        Guid EquipmentId = _Service.Create(Equipment);
        //************************** Retrieve the Resource group***************
        Entity ResourceGroup = _Service.Retrieve("constraintbasedgroup", new Guid("ResourceGroupId"), new ColumnSet(true));
        //********************* Get the constrains of Resource group***************
        System.Text.StringBuilder builder = new System.Text.StringBuilder(ResourceGroup["constraints"].ToString());
        //******* Assing the equipment to resouce group ***************
        builder.Replace("</Body>", " || resource[\"Id\"] ==" + EquipmentId.ToString("B") + " </Body>");

        ResourceGroup["constraints"] = builder.ToString();
        //**************************** Update Resource Group***************
        _Service.Update(ResourceGroup);

ليست هناك تعليقات:

إرسال تعليق