How do I update NetSuite Department isInactive via WSDL? - netsuite

I'm trying to update NetSuite Department via WSDL but I'm having an issue updating isInactive. Below is my code in C#:
var record = new com.netsuite.webservices.Department
{
internalId = dp.InternalId,
isInactive = dp.InActive
};
then called
var result = ServiceClient.update(record);
The Department's DEPARTMENT IS INACTIVE on NetSuite doesn't check whether I set it to true or false. What am I doing wrong here?

You forgot to set isInactiveSpecified
Try this:
var record = new com.netsuite.webservices.Department
{
internalId = dp.InternalId,
isInactive = dp.InActive,
isInactiveSpecified = true
};

You need to first .get() the record, set some properties, then .update() the record. Here's what works for me:
var ns = new NetSuite.NetSuiteService();
// passport info skipped
var departmentRef = new RecordRef
{
internalId = "1",
type = RecordType.department,
typeSpecified = true
};
var response = ns.get(departmentRef);
var department = response.record as Department;
department.isInactive = true;
ns.update(department);

Related

set lookup field & managed meta data field using jsom in sharepoint

Setting lookup field & managed meta data field value using jsom. Through jsom I will need to set the value into the list .
Setting the lookup and managed metadata columns through code
Try and modify the below sample code:
var clientContext = new SP.ClientContext(_spPageContextInfo.webAbsoluteUrl);
var list = clientContext.get_web().get_lists().getByTitle('TestList');
var itemCreateInfo = new SP.ListItemCreationInformation();
var listItem = list.addItem(itemCreateInfo);
var singleLookupColumn = new SP.FieldLookupValue();
singleLookupColumn.set_lookupId(2);
listItem.set_item('CustomLookup', singleLookupColumn);
var field = list.get_fields().getByInternalNameOrTitle("TestTaxonomy");
var taxField = clientContext.castTo(field, SP.Taxonomy.TaxonomyField);
var taxonomyCol = new SP.Taxonomy.TaxonomyFieldValue();
taxonomyCol.set_label("Test");
taxonomyCol.set_termGuid("23d03b66-5be6-512b-9fe3-ff13b9b4757c");
taxonomyCol.set_wssId(-1);
taxField.setFieldValueByValue(listItem, taxonomyCol);
listItem.update();
clientContext.load(listItem);
clientContext.executeQueryAsync(function(){
console.log("success");
},function(){
console.log("error");
});

How to get all subsidiaries showing in UI by RESTlet in Netsuite?

i could get all names, types, labels and available options for fields except subsidiary.
There are two options for subsidiary in Netsuite UI. But when i try to get by code, i could get only one subsidiary which was referred in Employee creation.
This is the code snippet.
function getFields(datain) {
var record = nlapiCreateRecord ( datain . recordtype );
var fields = record.getAllFields();
var requiredFields = {};
fields.forEach(function(fieldName){
var field = record.getField(fieldName);
if(field.mandatory === true) {
var id = field.getName();
var field_details = {}
field_details['Type'] = field.getType();
field_details['Label'] = field.getLabel();
if(field.getType() == 'select' || field.getType() == 'multiselect') {
var Options = field.getSelectOptions();
var selectOptions = {};
for(var i in Options) {
var opt_id = Options[i].getId();
selectOptions[opt_id] = Options[i].getText()
}
field_details['Options'] = selectOptions;
}
requiredFields[id]=field_details;
}
});
return requiredFields;
}
How to get all subsidiaries available in lead , customer or contact creation?
Subsidiaries are retrieved based on subsidiaries set in roles not on employee creation. Here before i have selected only one subsidiary in role.
If we select all subsidiaries for the appropriate role, we can get all subsidiaries which were selected in the role.

Creating dynamic customer group using suite script

I am trying to create dynamic customer group using suite script in Net suite, I am trying below code but always getting
system INVALID_KEY_OR_REF
Invalid savedsearch reference key 21.
I have checked it is valid save search, Please help I am doing something wrong.
function createDynamicGroup(savedSearchId, groupName) {
var saveSearchObj = nlapiLoadSearch('customer', savedSearchId);
var initValues = new Array();
initValues.grouptype = 'Customer';
initValues.dynamic = 'T';
var goupRecObj = nlapiCreateRecord('entitygroup', initValues);
goupRecObj.setFieldValue('groupname', groupName);
goupRecObj.setFieldValue('savedsearch',saveSearchObj.getId());
nlapiSubmitRecord(goupRecObj);
}
You need group type = 'CustJob' as well as using a public search id:
function createDynamicGroup(savedSearchId, groupName) {
var saveSearchObj = nlapiLoadSearch('customer', savedSearchId);
var initValues = {
grouptype: 'CustJob', // <-- use this
dynamic: 'T'
};
var goupRecObj = nlapiCreateRecord('entitygroup', initValues);
goupRecObj.setFieldValue('groupname', groupName);
goupRecObj.setFieldValue('savedsearch', savedSearchId);
return nlapiSubmitRecord(goupRecObj);
}

CRM 2013 to update statecode of Incident Resolution Entity

I am quite new to this part of CRM. I want to set the StateCode field of Incident Resolution Entity.
I am trying the following way -
IncidentResolution res = new IncidentResolution();
res.IncidentId = new EntityReference();
res.IncidentId.LogicalName =Incident.EntityLogicalName;
res.IncidentId.Id = new Guid(row["id"].ToString());
res.StateCode = new OptionSetValue((int)IncidentResolutionState.Completed)); //This Following gives the error as System.Nullable<IncidentResolution.StateCode> cannot be assigned to--It is readonly.
CloseIncidentRequest req = new CloseIncidentRequest();
req.IncidentResolution = res;
req.Status = new OptionSetValue();
req.Status.Value = 5; // Problem Solved
service.execute(req);
The problem i am facing is to set the StateCode property for Incident Resolution Entity.
Any help would be appreciated.
Thanks in Advance
you don't need to set the StateCode of the IncidentResolution, only the Status of CloseIncidentRequest:
IncidentResolution res = new IncidentResolution
{
Subject = "Resolved Sample Incident",
IncidentId = new EntityReference(Incident.EntityLogicalName, new Guid(row["id"].ToString()))
};
// Close the incident with the resolution.
CloseIncidentRequest req = new CloseIncidentRequest
{
IncidentResolution = res,
Status = new OptionSetValue(5)
};
service.execute(req);

CRM 2011 Retrieving lookup

I'm new in CRM development. I know a basic thing like "best practice for crm 2011"
I wanna understand now how to work with lookup fields. And I think I chose the easiest way for my self.
I have an costum entity "contract" it has 5 more field, 2 of these are lookups.
First lookup (agl_contractId) - it is a link by it self
Second lookup (agl_ClientId) - link to Client.
What do I need?
When I choose fill First lookup (agl_contractId), script should find in this contract a Client and copy-past it to current form.
I've done script but it isn't work... (((
function GetAccountFromContract()
{
XrmServiceToolkit.Rest.Retrieve(Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue(),
'agl_osnovnoy_dogovoridSet',
null,null,
function (result) {
var Id = Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue();
if (result.Id != null) {
var LookupData = new Array();
var LookupItem = new Object();
var lookuptextvalue = lookupvalue[0].name;
var lookupid = lookupvalue[0].id;
var lokupType = lookupvalue[0].entityType;
alert(lookupvalue);
alert(lookupData);
Xrm.Page.getAttribute("agl_accountid").setValue(lookupData);
}
},
function (error) {
equal(true, false, error.message);
},
false
);
}
If I understand you well: When you select Contract in agl_osnovnoy_dogovorid field, you want to pull Client property from that Contract and put it in agl_accountid field?
If that is right:
First, get Id of selected Contract (from agl_osnovnoy_dogovorid field)
var selectedContract = new Array();
selectedContract = Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue();
{
var guidSelectedContract = selectedContract[0].id;
//var name = selectedContract[0].name;
//var entType = selectedContract[0].entityType;
}
Second, retrieve Client from agl_osnovnoy_dogovorid. Your oData query will be like:
http://crmserver/org/XRMServices/2011/OrganizationData.svc/ContractSet(guid'" + guidSelectedContract + "')/CustomerId
(In example I'm using CustomerId field. For your case enter Schema Name of Client field).
Now, execute query and put result into agl_accountid field:
$.getJSON(
Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc/ContractSet(guid'" + guidSelectedContract + "')/CustomerId",
function(data){
if(data.d.CustomerId != null && data.d.CustomerId.Id != null && data.d.CustomerId.Id != "undefined")
{
//set agl_accountid field
Xrm.Page.getAttribute("agl_accountid").setValue([{id:data.d.CustomerId.Id, name:data.d.CustomerId.Name, typename:data.d.CustomerId.LogicalName}]);
}
});
Your using REST to retrieve data but also using FetchXml example to setup the agl_accoutid lookup.
Also some of the conditions are not clear … anyway … I’ve incorporated the change to your original post.
function GetAccountFromContract()
{
var aodLookupValue = Xrm.Page.getAttribute("agl_osnovnoy_dogovorid").getValue();
if (!aodLookupValue) return;
XrmServiceToolkit.Rest.Retrieve( aodLookupValue[0].id ,
'agl_osnovnoy_dogovoridSet', null,null,
function (result) {
var customer = result.d["your attribute name"];
if (customer) {
var LookupData = new Array();
var LookupItem = new Object();
var lookuptextvalue = customer.Name;
var lookupid = customer.Id;
var lokupType = customer.LogicalName;
alert(lookupvalue);
alert(lookupData);
Xrm.Page.getAttribute("agl_accountid").setValue(lookupData);
}
},
function (error) {
equal(true, false, error.message);
}, false );
}

Resources