I created a script and deployed it to automatically populate web store fields when new inventory items are created in our system.
The code works when a new item is created through the interface, but does not when a new item is uploaded via csv.
This is the code:
function userEventAfterSubmit(type) {
if (type == 'create') {
var newItem = nlapiLoadRecord('inventoryitem', nlapiGetNewRecord().getId());
var storeDisplayImage = nlapiGetFieldValue('storedisplayimage');
if (storeDisplayImage == '' || storeDisplayImage == null)
newItem.setFieldValue('storedisplayimage', 620128);
var storeDisplayThumbnail = nlapiGetFieldValue('storedisplaythumbnail');
if (storeDisplayThumbnail == '' || storeDisplayThumbnail == null)
newItem.setFieldValue('storedisplaythumbnail', 620127);
var urlComponent = nlapiGetFieldValue('urlcomponent');
if (urlComponent == '' || urlComponent == null)
newItem.setFieldValue('urlcomponent', nlapiGetFieldValue('storedisplayname'));
var pageTitle = nlapiGetFieldValue('pagetitle');
if (pageTitle == '' || pageTitle == null)
newItem.setFieldValue('pagetitle', nlapiGetFieldValue('storedisplayname'));
var storeDescription = nlapiGetFieldValue('storedescription');
if (storeDescription == '' || storeDescription == null)
newItem.setFieldValue('storedescription', nlapiGetFieldValue('salesdescription'));
var storeDetailedDescription = nlapiGetFieldValue('storedetaileddescription');
if (storeDetailedDescription == '' || storeDetailedDescription == null)
newItem.setFieldValue('storedetaileddescription', nlapiGetFieldValue('salesdescription'));
var metaTagHtml = nlapiGetFieldValue('metataghtml');
if (metaTagHtml == '' || metaTagHtml == null)
newItem.setFieldValue('metataghtml', '<meta name="description" content="' + nlapiGetFieldValue('salesdescription') + '">');
nlapiSubmitRecord(newItem);
}
}
And then this function is called as the "After Submit Function". Am I not calling in this in the right place for it to run for csv uploads?
This is my script deployment:
Goto "Setup > Import/Export > CSV Import preferences"
Make sure " RUN SERVER SUITESCRIPT AND TRIGGER WORKFLOWS" is checked.
Related
I have an array declared at the beginning and inside my MessageHandler function I capture the responses with if(event.message) and push the message in the array but when it comes to displaying them in a variable called "datos" in a whatsapp message it doesn't work . In the development environment by gupshup it works but when deploying it in whatsapp it doesn't.
var botScriptExecutor = require('bot-script').executor;
var scr_config = require('./scr_config.json');
var arr = [];
function MessageHandler(context, event) {
if (event.message == "Evento" || event.message == "Construccion" || event.message == "Servicio" || event.message == "Evento 1" || event.message == "Construccion 2" || event.message == "Servicio 3") {
json.categ = event.message;
}
if (event.message == "Saltillo" || event.message == "Monterrey" || event.message == "Otro" || event.message == "Saltillo 2" || event.message == "Monterrey 2" || event.message == "Otro 3") {
json.zona = event.message;
}
}
exports.array = json;
in my script defalt.js I work with the label of the "datos" variable
module.exports.datos = {
label_baas: datosSoli
}
var message = require('./index.js');
function datosSoli(options, event, context, callback) {
console.log("---------------------label datosSoli---------------------");
var info = "";
info = "categoria: " + message.array.categ + "zona: " + message.array.zona;
options.next_state = 'label_baaj';
options.data.datos = info;
console.log("-----------options.data.datos-------------", options.data.datos);
callback(options, event, context);
}
This is the flow of my conversation where the "datos" variable module is shown
enter image description here
I have a method below pulling specific fields that have null values.
Every record in the table has a status field of 1 or 0. 1 is active and 0 is inactive.
For the query below I only want to pull data for active records i.e status = 1
How can I modify this query to put in the condition for status = 1?
public List<FileModel> GetMyData()
{
var collectedData = _context.MyUploads.AsNoTracking().Where(t =>
t.FirstName == null ||
t.LastName == null ||
t.EmailAddress == null ||
t.Telephone == null)
.Select(x => _mapper.Map<FileModel>(x))
.ToList();
return collectedData;
}
You can chain two Where Linq extension method calls right after one another, like so:
public List<FileModel> GetMyData()
{
var collectedData = _context.MyUploads.AsNoTracking().Where(t =>
t.FirstName == null ||
t.LastName == null ||
t.EmailAddress == null ||
t.Telephone == null)
.Where(t => t.status == 1) // added this line...
.Select(x => _mapper.Map<FileModel>(x))
.ToList();
return collectedData;
}
you should just be able to change the where condition to the below
.Where(t => (t.FirstName == null || t.LastName == null || t.EmailAddress == null || t.Telephone == null) && t.status == 1)
The && means and, so its saying those fields are null and the status equals 1.
I am trying to import a logo of a web and its subsite in sharepoint 2013.
When I try to load the file for subsite then exception occur.
Value does not fall within the expected range
Here is my code
if (siteLogo != null)
{
File = web.GetFileByServerRelativeUrl(siteLogo);
Data = File.OpenBinaryStream();
customContext.Context.Load(File);
customContext.Context.ExecuteQuery();
}
First Time it works fine. But when it loads for subsite it generate exception.
I tried alot to solve this but unable to find the solution. Please help.
This is complete file
public Branding(SharePointClientContext customContext, string siteLogo, string alternateCss, ListItemCollection ltItemCollection, Microsoft.SharePoint.Client.Web web)
{
if (ltItemCollection != null)
{
ListItem item = ltItemCollection.Where(a => a.DisplayName == "Current").FirstOrDefault();
if (item.FieldValuesAsText != null && item.FieldValuesAsText.FieldValues["ThemeUrl"] != null && item.FieldValuesAsText.FieldValues["ThemeUrl"] != "")
{
string themeUrl = item.FieldValuesAsText.FieldValues["ThemeUrl"].Split(',')[1];
string themeFileName = themeUrl.Substring(themeUrl.LastIndexOf('/') + 1).ToLower();
ListItem selectedTheme = ltItemCollection.Where(a =>
a.FieldValuesAsText.FieldValues["ThemeUrl"].Split(',')[1].Substring(a.FieldValuesAsText.FieldValues["ThemeUrl"].Split(',')[1].LastIndexOf('/') + 1) == themeFileName
&& a.DisplayName != "Current").FirstOrDefault();
this.Theme = selectedTheme.DisplayName;
}
}
if (siteLogo != null)
{
File = web.GetFileByServerRelativeUrl(siteLogo);
Data = File.OpenBinaryStream();
customContext.Context.Load(File);
customContext.Context.ExecuteQuery();
File = null;
}
if (alternateCss != null && alternateCss != "")
{
CssFile = web.GetFileByServerRelativeUrl(web.SiteLogoUrl);
CssData = CssFile.OpenBinaryStream();
web.Context.Load(CssFile);
web.Context.ExecuteQuery();
CssFile = null;
}
}
And calling this in following way.
SharePointConstants.branding.Add(new Branding(customContext, siteLogo, AlternateCss, ltItemCollection, web));
I am getting an error after auto populating a Look-UP though javascript. My code is below. It is working and I am able to autopopulate. But when I click on the autopopulated filed I am getting an error. Also an error while saving the record.Errors are :
1) 'ryan_leadengagementprincipalassignment with id = ******* does not exist' (When I click on the populated Lookup value)
2) The requested record is not found or you do not have sufficient privilege to view it. (While saving the record)
Code:
var LEPAccountLookup= crmForm.all.customerid.DataValue;
if (LEPAccountLookup!= null && LEPAccountLookup!= 'undefined')
{
var LEPAccountID= LEPAccountLookup[0].id;
var LEPAccountxml = '' +
'<?xml version=\'1.0\' encoding=\'utf-8\'?>' +
'<soap:Envelope xmlns:soap=\'http://schemas.xmlsoap.org/soap/envelope/\' xmlns:xsi=\'http://www.w3.org/2001/XMLSchema-instance\' xmlns:xsd=\'http://www.w3.org/2001/XMLSchema\'>' +
GenerateAuthenticationHeader() +
' <soap:Body>' +
' <RetrieveMultiple xmlns=\'http://schemas.microsoft.com/crm/2007/WebServices\'>' +
' <query xmlns:q1=\'http://schemas.microsoft.com/crm/2006/Query\' xsi:type=\'q1:QueryExpression\'>' +
' <q1:EntityName>ryan_leadengagementprincipalassignment</q1:EntityName>' +
' <q1:ColumnSet xsi:type=\'q1:AllColumns\' />' +
' <q1:Distinct>false</q1:Distinct>' +
' <q1:Criteria>' +
' <q1:FilterOperator>And</q1:FilterOperator>' +
' <q1:Conditions>' +
' <q1:Condition>' +
' <q1:AttributeName>ryan_accountnameid</q1:AttributeName>' +
' <q1:Operator>Like</q1:Operator>' +
' <q1:Values>' +
' <q1:Value xsi:type=\'xsd:string\'>' + LEPAccountID + '</q1:Value>' +
' </q1:Values>' +
' </q1:Condition>' +
' </q1:Conditions>' +
' </q1:Criteria>' +
' </query>' +
' </RetrieveMultiple>' +
' </soap:Body>' +
'</soap:Envelope>' +
'';
//alert(LEPAccountxml);
var xmlHttpRequest = new ActiveXObject('Msxml2.XMLHTTP');
xmlHttpRequest.Open('POST', '/mscrmservices/2007/CrmService.asmx', false);
xmlHttpRequest.setRequestHeader('SOAPAction','http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple');
xmlHttpRequest.setRequestHeader('Content-Type', 'text/xml; charset=utf-8');
xmlHttpRequest.setRequestHeader('Content-Length', LEPAccountxml.length);
xmlHttpRequest.send(LEPAccountxml);
var resultLEPAccountxml = xmlHttpRequest.responseXML;
//alert(resultLEPAccountxml);
//----------------------------------------------------------------------------------------------------------------------
var entityNodes = resultLEPAccountxml.selectNodes('//RetrieveMultipleResult/BusinessEntities/BusinessEntity');
for (var i = 0; i < entityNodes.length; i++) {
var entityNode = entityNodes[i];
var LEPAccountNode = entityNode.selectSingleNode("q1:ryan_accountnameid");
var LEPAccountNodename = entityNode.selectSingleNode('./q1:ryan_accountnameid/#name');
var LEPParentPracAreaNode = entityNode.selectSingleNode("q1:ryan_parentpracticeareaid");
var LEPParentPracAreaNodename = entityNode.selectSingleNode('./q1:ryan_parentpracticeareaid/#name');
var LEPPracAreaNode = entityNode.selectSingleNode("q1:ryan_practiceareaid");
var LEPPracAreaNodename = entityNode.selectSingleNode('./q1:ryan_practiceareaid/#name');
var LEPLegalEntityNode= entityNode.selectSingleNode("q1:ryan_legalid");
var LEPLegalEntityNodename = entityNode.selectSingleNode('./q1:ryan_legalid/#name');
var LEPNode= entityNode.selectSingleNode("q1:ryan_leadengagementid");
var LEPNodename = entityNode.selectSingleNode('./q1:ryan_leadengagementid/#name')
var LEPAccountid= (LEPAccountNode == null) ? null : LEPAccountNode.text;
var LEPAccountname= (LEPAccountNodename == null) ? null : LEPAccountNodename.text;
var LEPPareantPracAreaid= (LEPParentPracAreaNode == null) ? null : LEPParentPracAreaNode.text;
var LEPPareantPracAreaname= (LEPParentPracAreaNodename == null) ? null : LEPParentPracAreaNodename.text;
var LEPPracAreaid= (LEPPracAreaNode == null) ? null : LEPPracAreaNode.text;
var LEPPracAreaname= (LEPPracAreaNodename == null) ? null : LEPPracAreaNodename.text;
var LEPLegalEntityid= (LEPLegalEntityNode == null) ? null : LEPLegalEntityNode.text;
var LEPLegalEntityname= (LEPLegalEntityNodename == null) ? null : LEPLegalEntityNodename.text;
var LEPEntityid= (LEPNode == null) ? null : LEPNode.text;
var LEPEntityname= (LEPNodename == null) ? null : LEPNodename.text;
//alert(LEPAccountid);
//(LEPAccountname);
var LEPAccount = crmForm.all.customerid.DataValue;
var LEPLE = crmForm.all.ryan_ryanlegalentityid.DataValue;
var LEPPPA = crmForm.all.ryan_parentpracticearea2id.DataValue;
var LEPPA = crmForm.all.ryan_practiceareaid.DataValue;
if((LEPAccount != null) &&(LEPLE != null) && (LEPPPA != null) && (LEPPA != null))
{
if ((LEPAccountid== LEPAccount[0].id) && (LEPLegalEntityid== LEPLE[0].id) && (LEPPareantPracAreaid== LEPPPA[0].id) && (LEPPracAreaid== LEPPA[0].id))
{
var lookup = [];
var lookupValue = new Object();
lookupValue.id = LEPEntityid;
lookupValue.typename = 'ryan_leadengagementprincipalassignment';
lookupValue.name = LEPEntityname;
lookup[0] = lookupValue;
crmForm.all.ryan_leadengagementprincipalid.DataValue = lookup;
crmForm.all.ryan_leadengagementprincipalid.ForceSubmit = true;
}
}
}
}
There is likely something wrong with your SOAP call. When you debug it, does resultLEPAccountXml have an xml response string? or is it just returning an error/empty set? (it appears you were alerting that and have commented it out)
Unfortunately I'm not familiar enough with your particular data model to verify that you are querying for the same table that you are attempting to populate. Is the ryan_leadengagementid field on the ryan_leadengagementprincipalassignment table indeed the correct field to use to set the lookup on whatever form you are executing this script (ie is ryan_leadengagementprincipalid a lookup to the ryan_leadengagementprincipalassignment table)? If you are setting the lookup for the wrong table, then that will cause an issue that looks exactly like this.
Also (as a side note), it appears you are doing a RetrieveMultiple, and looping through and setting the target field multiple times potentially - is this the intended functionality (setting that lookup based on all the leadengagementprincipalassignment results)? The setting of the lookup field looks fine, so I suspect it is the code to retrieve the values which should be used to set the lookup that is the culprit here.
I have a plugin registered in Post operation that needs to update multiple fields in CRM using data from an XML file. Currently I am using the following code:
if (node["node1"] != null)
{
var sId = sElement.GetElementsByTagName("pId")[0].InnerText;
Guid sGUID = new Guid(sId);
sEntity["Attrib1"] = sGUID;
service.Update(sEntity);
}
if (node["node2"] != null)
{
var sMax = sElement.GetElementsByTagName("pMax")[0].InnerText;
sEntity["Attrib2"] = sMax;
service.Update(sEntity);
}
if (node["node3"] != null)
{
var sMin = sElement.GetElementsByTagName("pMin")[0].InnerText;
sEntity["Attrib3"] = sMin;
service.Update(sEntity);
}
So I am calling the service.Update each time I need to update and in the above case 3 times.
Is there a better way to accomplish what I am trying to do and call the service.Update only one time?
You can just do a single update in the end (eventually you can add a check in case none of the fields changed, to avoid a useless update):
if (node["node1"] != null)
{
var sId = sElement.GetElementsByTagName("pId")[0].InnerText;
Guid sGUID = new Guid(sId);
sEntity["Attrib1"] = sGUID;
}
if (node["node2"] != null)
{
var sMax = sElement.GetElementsByTagName("pMax")[0].InnerText;
sEntity["Attrib2"] = sMax;
}
if (node["node3"] != null)
{
var sMin = sElement.GetElementsByTagName("pMin")[0].InnerText;
sEntity["Attrib3"] = sMin;
}
service.Update(sEntity);