SharePoint Yes/No fields not updating from Power Automate - sharepoint

I have a simple Flow to create an item when a new email arrives:
When a new email arrives > Parse JSON > Create item
The flow does work however, none of the Yes/No fields are not updating to Yes when the incoming value is true; the default value is No so false values are working as expected.
When a new email arrives
{ ... "Driver": true, ... }
Parse JSON
{
...
"Driver": true,
...
}
Create item
INPUTS
...
Driver
true
...
OUTPUTS
...
Driver
true
...
List Item in SharePoint
Driver (Yes/No) is un-checked/false
I have read the solution to Flow fails on Yes/No column (Big Flow) but to no avail.
https://powerusers.microsoft.com/t5/Using-Flows/Flow-fails-on-Yes-No-column-Big-Flow/m-p/35116#M1086
To confirm, I have unsuccessfully tried to add the following dynamic content options:
// In-correctly assumed the below line should work since a Yes/No field is a simple Boolean field;
// returns true but doesn't check the Driver checkbox in Item
body('Parse_JSON')?['json']?['Driver']
// Solution to Flow fails on Yes/No column (Big Flow);
// https://powerusers.microsoft.com/t5/Using-Flows/Flow-fails-on-Yes-No-column-Big-Flow/m-p/35116#M1086
// returns true but doesn't check the Driver checkbox in Item
equals(body('Parse_JSON')?['json']?['Driver'], true)
// All returns true but doesn't check the Driver checkbox in Item
if(body('Parse_JSON')?['json']?['Driver'], true, false)
if(body('Parse_JSON')?['json']?['Driver'], 'True', 'False')
if(equals(body('Parse_JSON')?['json']?['Driver'], true), true, false)
if(equals(body('Parse_JSON')?['json']?['Driver'], true), 'True', 'False')
// Throws error; and Flow fails as expected
if(body('Parse_JSON')?['json']?['Driver'], 'Yes', 'No')
if(equals(body('Parse_JSON')?['json']?['Driver'], true), 'Yes', 'No')
Now, I am just guessing so what am I missing?!
To summarise, my question is how do I successfully update Yes/No fields when creating an item from a MS Flow?

I stumbled onto a work-around, and accepted solution, where using the Send an HTTP request to SharePoint action to update the Description (Display Text) & URL fields of a Hyperlink field.
I found this post most helpful: Updating a Hyperlink field (both url and description) using Flow?
I used the same approach to update all Yes/No fields to Yes when the incoming value is true. Here are the key settings others may find useful.
Site Address: https://MyFakeSite.sharepoint.com/
Method: POST
Url: _api/web/lists/GetByTitle('MyFakeList')/Items(#{body('Create_item')?['ID']})
Headers: {
"Accept": "application/json;odata=verbose",
"Content-Type": "application/json;odata=verbose",
"X-HTTP-Method": "MERGE",
"IF-MATCH": "*"
}
Body: {
'__metadata': {
'type': 'SP.Data.MyFakeListItem'
},
'Driver': #{toLower(string(equals(body('Parse_JSON')?['json']?['Driver'], true)))},
...
}

Related

How to get Tabulator to populate a headerFilter ONLY when it is clicked

I'm using Tabulator with ajax to pull paginated data to the table. I'd like to use headerFilters with valuesURL but the AJAX request is a POST not a GET and valuesURL only works with GET. He alternative is to use values, but that seems to want to pull the values each time the data is refreshed. I need the headerFilter options to be refreshed ONLY when it the input box is clicked. Psuedo-process below...
Load all data
user clicks one headerFilter "City"
ajax called via POST to get list of relevant values for "City"
headerFilter is populated with list, which is then presented to the user via the drop down
Is this possible?
I've tried using a function in headerFilterParams to get the values but each headerFilter is refreshed when the data is refreshed as opposed to just the one that was clicked.
You can use the headerFilter in combination with a custom header filter component that makes the AJAX call to get the values when the header filter is clicked.
Example:
var cityFilter = function(headerValue, rowValue, rowData, filterParams){
// code to filter data based on selected city
};
// Custom header filter component
var customCityFilter = function(header) {
var self = this;
self.element = document.createElement("input");
self.element.setAttribute("type", "text");
self.element.setAttribute("placeholder", "Type to filter");
// Add click event to make the AJAX call when the input box is clicked
self.element.addEventListener("click", function() {
// Make the AJAX call to get the list of relevant values for "City"
// Replace with your own AJAX code
// Example using jQuery
$.ajax({
type: "POST",
url: "your_url",
data: {},
success: function(data) {
// Populate the headerFilter with the list of values
header.setFilterValues(data);
}
});
});
// Return the custom filter component
return self.element;
};
// Initialize the table with the custom header filter
var table = new Tabulator("#example-table", {
columns:[
{title:"City", field:"city", headerFilter:"custom", headerFilterParams:{component:customCityFilter}, headerFilterFunc:cityFilter},
// other columns
],
});

How to prevent axios from sending null values?

I have an axios.post() request configured to update a document in my MongoDB collection by sending current state, updated by textfields.
I have my state initially setup to null:
this.state = {
editedCustomer: {
name: null,
surname: null,
alias: null,
email: null,
phoneNo: null,
_id: null
},
}
These values are updated directly from text fields, so whenever a textfield receives input it updates the state, which is then sent with axios like this:
axios.patch(`${APIURL}/customers/updateCustomer`, {
'name': this.state.editedCustomer.name,
'surname': this.state.editedCustomer.surname,
'alias': this.state.editedCustomer.alias,
'email': this.state.editedCustomer.email,
'phoneNo': this.state.editedCustomer.phoneNo,
'_id': this.state.editedCustomer._id
})
However, my problem is, if I only update some fields (say I only wanna update the customer's name), the rest of these fields are being posted to my backend as null and my database being populated with the updated values, with null now replacing the rest of the fields.
Is there any way to only post non-null values with axios, or should the change be in my /updateCustomer route within my backend. Thanks :)
Axios is sending null because if you're updating only certain values, the other values that are not being supplied are null.
So what you should do is in your /updateCustomer route in your backend, you only update the values that are passed in from axios instead of updating the whole object.
You should just map over that Object using Object.keys and "filter" the values that are null
let data = {};//<- Data to send with Axios
Object.keys(this.state.editedCustomer).map((key) => {
if(editedCustomer[key]) {
data[key] = editedCustomer[key]
}
});
const dataToSend = JSON.stringify(data);
then you just post your dataToSend with Axios/fetch...

How to get the fields of an address from a location record using SuiteScript

Context: A RESTlet written in SuiteScript v1, but I'll use v2 if I must.
Important: Solution must work serverside.
The location record has a field titled Main Address. The field id is mainaddress_text.
When I edit the Main Address field using the NetSuite website it presents me with the normal address editing form with the normal address fields, so it appears that NetSuite stores the address like it does the addresses on, for example, the customer record, in fields called Country, Attention, Addressee, Phone etc.
I want to get the values of these fields, but I can't work out how.
I have loaded the location using
location = nlapiLoadRecord('location', locationid)
The schema browser (https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/schema/record/location.html) suggests there is a field called mainAddress of type Address.
I have attempted to access the mainAddress field using statements like these:
location.getField('mainaddress') //returns null
location.getSubList('mainaddress') //returns null
location.getLineItemCount('mainaddress') //returns -1
location.getFieldValue('mainaddress') //returns null
location.getFieldText('mainaddress') //returns null
But no success.
I also tried location.getLineItemCount('addressbook') in case there was a field named like in the customer record but that returned -1.
The records browser (https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/script/record/location.html) suggests there is a field called addrtext of type Address.
I have attempted to access the addrtext field using statements like these:
location.getField('addrtext') //returns null
location.getSubList('addrtext') //returns null
location.getLineItemCount('addrtext') //returns -1
location.getFieldValue('addrtext') //returns null
location.getFieldText('addrtext') //returns null
But no success.
The records browser also describes fields called addr1, addr2, addr3, addressee, attention, city and so on.
I have attempted to access those fields using statements like these:
location.getFieldValue('attention') //returns null
location.getFieldValue('addressee') //returns null
location.getFieldValue('addr1') //returns null
location.getFieldValue('addr2') //returns null
location.getFieldValue('addr3') //returns null
location.getFieldValue('city') //returns null
location.getFieldValue('state') //returns null
location.getFieldValue('country') //returns null
But no success.
The only way I've found to get the address data is using location.getFieldValue('mainaddress_text') but that returns the address as one string with the parts of the address delimited by <br>-tokens.
How can I get the individual address fields?
I suggest stringifying the record to see what's in it with JSON.stringify(location). The address fields are normally stored in addr1, etc...
It is possible that the address fields weren't set from the UI. I have seen some scripts that just set the mainaddress_text field, but neglect to change the individual fields as well which causes issues in the long run cause mainaddress_text won't match the other address fields (addr1, addr2, etc...).
You may want to try searching for the address fields, here's how to do it in SS 1.0:
var locationSearch = nlapiSearchRecord("location", null,
[
["internalid", "anyof", "2"] //Change internal id
],
[
new nlobjSearchColumn("attention", 'address', null),
new nlobjSearchColumn("addressee", 'address', null),
new nlobjSearchColumn("address1", null, null),
new nlobjSearchColumn("address2", null, null),
new nlobjSearchColumn("address3", null, null),
new nlobjSearchColumn("city", null, null),
new nlobjSearchColumn("state", null, null),
new nlobjSearchColumn("country", null, null),
new nlobjSearchColumn("zip", null, null),
new nlobjSearchColumn("phone", null, null)
]
);
if (results)
{
var result = results[0];
return {
attention: result.getValue('attention', 'address'),
addressee: result.getValue('addressee', 'address'),
address1: result.getValue('address1'),
address2: result.getValue('address2'),
address3: result.getValue('address3'),
city: result.getValue('city'),
state: result.getValue('state'),
country: result.getValue('country'),
zip: result.getValue('zip'),
phone: result.getValue('phone')
};
}
Give this a try:
nlapiLoadRecord("location", locationID, {recordmode: "dynamic"})
.viewSubrecord("mainaddress")
.getFieldValue('addrtext');
I opened a Location record in a browser, and opened a console from there to load the nlobjRecord. Looking at the fields I see there is a mainaddress2_set field which is set by a nlapiViewSubrecord("mainaddress")
I couldn't make a call to the viewSubrecord("mainaddress") from the client side console, but I did create a simple suitelet to load the Location record and print the address.
function GET(request, response){
var r = nlapiLoadRecord("location", "123456", {recordmode: "dynamic"});
response.write(r.viewSubrecord("mainaddress").getFieldValue('addrtext'));
response.write(r.viewSubrecord("mainaddress").getFieldValue('addr1'));
// etc.
}

Getting select2 to refresh data using ajax on dropdown

I have the following JavaScript to populate dropdown list using select2 https://select2.github.io/
It works fine, and populates the list on the first load of the page.
From then on it does not refresh the list even when data is added because it only does the AJAX call once. Even if I reload the page, the dropdown list is not refreshed and the AJAX call is not triggered (unless I close and reopen the browser, then the AJAX call is fired)
Is there a way to undertake the ajax call each time the dropdown is opened. I tried the .on("select2-open") option but didn't have any luck.
Sorry JavaScript is not something I know much about.
$("#Location").select2({
placeholder: "Select a known location", // Placeholder text
allowClear: true, //Allows deselection of chosen address
ajax: {
url: '/AlertInterface/NewAlertLocations', // Where we want the ajax to call
dataType: 'json', // The datatype we are expecting to be returned
type: "GET", //Just a get method
//Data: allows us to pass a parameter to the controller
data: function (query) {
console.log(query)
return { search: query.term }
},
//processes the results from the JSON method and gives us the select list
processResults: function (data) {
console.log(data)
return {
results: JSON.parse(data)
};
}
}
});
EDIT:
I did try to use
$("#Location").on("select2:open", function () { $("#Location").select2(); })
but that didn't help. :-(
You have a syntax error in your code.
Please check the below code,
$("#Location").select2({
placeholder: "Select a known location", // Placeholder text
allowClear: true, //Allows deselection of chosen address
ajax: {
url: '/AlertInterface/NewAlertLocations', // Where we want the ajax to call
dataType: 'json', // The datatype we are expecting to be returned
type: "GET", //Just a get method
//Data: allows us to pass a parameter to the controller
data: function (query) {
console.log(query)
return { search: query.term }
},
//processes the results from the JSON method and gives us the select list
processResults: function (data) {
console.log(data)
return {
results: JSON.parse(data)
};
}
}
});

Kendo UI Grid search as type example

I would like to search datagrid in Kendo UI during typing into input field above the grid.
How can I do it?
Thanks for any advice.
Here is example of columns:
$("#grid").kendoGrid({
dataSource: dataPacket,
filterable: true,
pageSize: 10,
pageable: true,
sortable: true,
reorderable: true,
resizable: true,
columnMenu: true,
height: 550,
toolbar: ["create", "save", "cancel"],
columns: ["id",
"username",
"name",
"surname",
"email",
{
field :"created",
title : "Created at",
format: "{0:M/d/yyyy}",
parseFormats: ["dd-MM-yyyy"],
type: "date"
},
Kendo make this thing really easy for you, what is needed is to create a filter and pass it to the DataSource.
http://docs.telerik.com/kendo-ui/api/framework/datasource#methods-filter
However, this problem must be divided into two different tasks:
a) Capture the key events in the search box, throttle it and start the search "operation".
b) Build a filter and pass it to the DataSource.
So for throttling the keyboard events, we need a timeout. Or use the throttle function from underscorejs. Why? We don't wanna trigger a search operation on each key press. Only 250 milliseconds (this number is up to you) after the last keystroke.
Here is your sample HTML
<input type="text" id="search" />
Here is your sample script. I wrap everything as a self calling function as you don't wanna create a mess declaring global variables.
(function($, kendo){
// ID of the timeout "timer" created in the last key-press
var timeout = 0;
// Our search function
var performSearch = function(){
// Our filter, an empty array mean "no filter"
var filter = [];
// Get the DataSource
var dataSource = $('#grid').data('kendoGrid').dataSource;
// Get and clean the search text.
var searchText = $.trim($('#search').val());
// Build the filter in case the user actually enter some text in the search field
if(searchText){
// In this case I wanna make a multiple column search so the filter that I want to apply will be an array of filters, with an OR logic.
filter.push({
logic: 'or',
filters:[
{ field: 'username', operator: 'contains', value: searchText },
{ field: 'name', operator: 'contains', value: searchText },
{ field: 'surname', operator: 'contains', value: searchText },
{ field: 'email', operator: 'contains', value: searchText }
]
});
}
// Apply the filter.
dataSource.filter(filter);
};
// Bind all the keyboard events that we wanna listen to the search field.
$('#search').on('keyup, keypress, change, blur', function(){
clearTimeout(timeout);
timeout = setTimeout(performSearch, 250);
});
})(window.jQuery, window.kendo);
Bottom-line: Make sure you are using the right DataSource configuration.
If you configured serverFiltering = true, this filtering logic will be part of your Ajax request, so your server will have to interpret and perform the filtering on server-side.
In case you configured serverFiltering = false all this filtering logic will be evaluated on client side using JavaScript (damn fast!). And in this case, the schema (what data-type is expected on each column) must be also well-configured.

Resources