CAML Query Null Hyperlink Field Causes list to not appear - sharepoint-2013

My list has two hyperlink fields, all new items will have both fields filled but some older items that I have to add do not have both. First, I added a few of the more recent items that have both hyperlinks to test that my CAML Query worked, and it did. Until I added an item that did not have both hyperlink fields filled in.
I've tried adding spaces to the field, does not work.
My query:
var hclientContext = new SP.ClientContext.get_current();
var hList = hclientContext.get_web().get_lists().getByTitle('HRReportsList');
// New caml for getting list based on view
var camlQueryHR = new SP.CamlQuery();
camlQueryHR.set_viewXml('<View Scope="RecursiveAll"><Query><Where><And><Eq><FieldRef Name="Year"/>' +
'<Value Type="Text">2019</Value></Eq><Eq><FieldRef Name="Report_x0020_Type"/>' +
'<Value Type="Choice">Turnover</Value></Eq></And></Where>' +
'<OrderBy><FieldRef Name="YYYYMM" Ascending="False" /></OrderBy>' +
'</Query><RowLimit>50</RowLimit><QueryOptions>' +
'<ViewAttributes Scope="Recursive" /></QueryOptions></View>');
this.hcollListItem = hList.getItems(camlQueryHR);
// end of caml for list view
//this.ncollListItem = nList.getItems("");
hclientContext.load(hcollListItem);
hclientContext.executeQueryAsync(
Function.createDelegate(this, this.onQuerySucceeded),
Function.createDelegate(this, this.onQueryFailed)
);
}
to get items I have some HTML, for example:
hListItem.get_item('InfographicLink').get_description() + '</a></br></br>' +
'<a href="' + hListItem.get_item('ReportLink').get_url() + '" target="_blank">' +
hListItem.get_item('ReportLink').get_description() + '</a></div>';
Error in the console is: 'Unable to get property 'get_url' of undefined or null reference'
Not a surprise, I just don't know how to get it to work knowing that I need to allow some hyperlinks to be empty.

Add a check to these two hyperlink fields, make sure they are not null like this:
while (listItemEnumerator.moveNext())
{
var hListItem = listItemEnumerator.get_current();
if(hListItem.get_item("ReportLink") && hListItem.get_item("InfographicLink"))
{
listItemInfo += hListItem.get_item('InfographicLink').get_description() + '</a></br></br>' +
'<a href="' + hListItem.get_item('ReportLink').get_url() + '" target="_blank">' +
hListItem.get_item('ReportLink').get_description() + '</a></div>';
}
}
Here is a similar question for your reference:
JSOM get_url of image null or undefined

Related

power bi DAX hierarchical table concatenation of names

Since two days I'm on a problem and I can't solve it so I come here to ask some help...
I have that bit of dax that basically take the path of a hierarchical table (integers) and take the string names of the 2 first in the path.
the names I use:
'HIERARCHY' the hierarchical table with names, id, path, nbrItems, string
mytable / addedcolumn1/2 the new table used to emulate the for loop
DisplayPath =
var __Path =PATH(ParentChild[id], ParentChild[parent_id])
var __P1 = PATHITEM(__Path,1) var __P2 = PATHITEM(__Path,2)
var l1 = LOOKUPVALUE(ParentChild[Place],ParentChild[id],VALUE(__P1))
var l2a = LOOKUPVALUE(ParentChild[Place],ParentChild[id],VALUE(__P2))
var l2 = if(ISBLANK(l2a), "", " -> " & l2a)
return CONCATENATE(l1,l2)
My problem is... I don't know the number of indexes in my path, can go from 0 to I guess 15...
I've tried some things but can't figure out a solution.
First I added a new column called nbrItems which calculate the number of items in the list of the path.
The two columns:
Then I added that bit of code that emulates a for loop depending on the number of items in the path list, and I'd like in it to
get name of parameters
concatenate them in one string that I can return and get
string =
var n = 'HIERARCHY'[nbrItems]
var mytable = GENERATESERIES(1, n)
var addedcolumn1 = ADDCOLUMNS(mytable, "nom", /* missing part: get name */)
var addedcolumn2 = ADDCOLUMNS(addedcolumn1, "string", /* missing part: concatenate previous concatenated and new name */)
var mymax = MAXX(addedcolumn2, [Value])
RETURN MAXX(FILTER(addedcolumn2, [Value] = mymax), [string])
Full table:
Thanks for your help in advance!
Ok, so after some research and a lot of try and error... I've came up to a nice and simple solution:
The original problem was that I had a hierarchical table ,but with all data in the same table.
like so
What I did was, adding a new "parent" column with this dax:
parent =
var a = 'HIERARCHY'[id_parent]
var b = CALCULATE(MIN('HIERARCHY'[libelle]), FILTER(ALL('HIERARCHY'), 'HIERARCHY'[id_h] = a))
RETURN b
This gets the parent name from the id_parent (ref. screen).
then I could just use the path function, not on the id's but on the names... like so:
path = PATH('HIERARCHY'[libelle], 'HIERARCHY'[parent])
It made the problem easy because I didn't need to replace the id's by there names after this...
and finally to make it look nice, I used some substitution to remove the pipes:
formated_path = SUBSTITUTE('HIERARCHY'[path], "|", " -> ")
final result

M & Power Query: How to use the $Skip ODATA expression within a loop?

Good afternoon all,
I'm trying to call all of the results within an API that has:
6640 total records
100 records per page
67 pages of results (total records / records per page)
This is an ever growing list so I've used variables to create the above values.
I can obviously use the $Skip ODATA expression to get any one of the 67 pages by adding the expression to the end of the URL like so (which would skip the first 100, therefore returning the 2nd page:
https://psa.pulseway.com/api/servicedesk/tickets/?$Skip=100
What I'm trying to do though is to create a custom function that will loop through each of the 67 calls, changing the $Skip value by an increment of 100 each time.
I thought I'd accomplished the goal with the below code:
let
Token = "Token",
BaseURL = "https://psa.pulseway.com/api/",
Path = "servicedesk/tickets/",
RecordsPerPage = 100,
CountTickets = Json.Document(Web.Contents(BaseURL,[Headers = [Authorization="Bearer " & Token],RelativePath = Path & "count"])),
TotalRecords = CountTickets[TotalRecords],
GetJson = (Url) =>
let Options = [Headers=[ #"Authorization" = "Bearer " & Token ]],
RawData = Web.Contents(Url, Options),
Json = Json.Document(RawData)
in Json,
GetPage = (Index) =>
let Skip = "$Skip=" & Text.From(Index * RecordsPerPage),
URL = BaseURL & Path & "?" & Skip,
Json = GetJson(URL)
in Json,
TotalPages = Number.RoundUp(TotalRecords / RecordsPerPage),
PageIndicies = {0.. TotalPages - 1},
Pages = List.Transform(PageIndicies, each GetPage(_))
in
Pages
I got all happy when it successfully made the 67 API calls and combined the results into a list for me to load in to a Power Query table, however what I'm actually seeing is the first 100 records repeated 67 times.
That tells me that my GetPage custom function which handles the $Skip value isn't changing and is stuck on the first one. To make sure the Skip index was generating them properly I duplicated the query and changed the code to load in the $Skip values and see what they are, expecting them all to be $Skip=0, what I see though is the correct $Skip values as below:
Image showing correct Skip values
It seems everything is working as it should be, only I'm only getting the first page 67 times.
I've made a couple of posts on other community site around this issue before but I realise the problem I was (poorly) describing was far too broad to get any meaningful assistance. I think now I've gotten to the point where I understand what my own code is doing and have really zoomed in to the problem - I just don't know how to fix it when I'm at the final hurdle...
Any help/advice would be massively appreciated. Thank you.
Edit: Updated following #RicardoDiaz answer.
let
// Define base parameters
Filter = "",
Path = "servicedesk/tickets/",
URL = "https://psa.pulseway.com/api/",
Token = "Token",
Limit = "100",
// Build the table based on record start and any filters
GetEntityRaw = (Filter as any, RecordStart as text, Path as text) =>
let
Options = [Headers=[ #"Authorization" = "Bearer " & Token ]],
URLbase = URL & Path & "?bearer=" & Token & "&start=" & RecordStart & "&limit=" & Text.From(Limit),
URLentity = if Filter <> null then URLbase & Filter else URLbase,
Source = Json.Document(Web.Contents(URLentity, Options)),
Result = Source[Result],
toTable = Table.FromList(Result, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
toTable,
// Recursively call the build table function
GetEntity = (optional RecordStart as text) as table =>
let
result = GetEntityRaw(Filter, RecordStart, Path),
nextStart = Text.From(Number.From(RecordStart) + Limit),
nextTable = Table.Combine({result, #GetEntity(nextStart)}),
check = try nextTable otherwise result
in
check,
resultTable = GetEntity("0")
in
resultTable
As I couldn't test your code, it's kind of hard to provide you a concrete answer.
Said that, please review the generic code I use to connect to an api and see if you can find where yours is not working
EDIT: Changed api_record_limit type to number (removed the quotation marks)
let
// Define base parameters
api_url_filter = "",
api_entity = "servicedesk/tickets/",
api_url = "https://psa.pulseway.com/api/",
api_token = "Token",
api_record_limit = 500,
// Build the table based on record start and any filters
fx_api_get_entity_raw = (api_url_filter as any, api_record_start as text, api_entity as text) =>
let
api_url_base = api_url & api_entity & "?api_token=" & api_token & "&start=" & api_record_start & "&limit=" & Text.From(api_record_limit),
api_url_entity = if api_url_filter <> null then api_url_base & api_url_filter else api_url_base,
Source = Json.Document(Web.Contents(api_url_entity)),
data = Source[data],
toTable = Table.FromList(data, Splitter.SplitByNothing(), null, null, ExtraValues.Error)
in
toTable,
// Recursively call the build table function
fxGetEntity = (optional api_record_start as text) as table =>
let
result = fx_api_get_entity_raw(api_url_filter, api_record_start, api_entity),
nextStart = Text.From(Number.From(api_record_start) + api_record_limit),
nextTable = Table.Combine({result, #fxGetEntity(nextStart)}),
check = try nextTable otherwise result
in
check,
resultTable = fxGetEntity("0"),
expandColumn = Table.ExpandRecordColumn(
resultTable,
"Column1",
Record.FieldNames(resultTable{0}[Column1]),
List.Transform(Record.FieldNames(resultTable{0}[Column1]), each _)
)
in
expandColumn
QUESTION TO OP:
Regarding this line:
Result = Source[Result],
Does the json return a field called result instead of data?

Shiny server-side updateSelectizeInput does not create selection list

The following code produces an empty selection box whereas I expected a list of state abbreviation + name pairs.
updateSelectizeInput(session, 'selectizer',
server=TRUE,
label=NULL,
choices = cbind(abb=state.abb, name=state.name),
options = list(render = I(
'{
option: function(item, escape) {
return "<div>" + escape(item.abb) + " " +
escape(item.name) + "</div>";
}
}'), maxItems=3, placeholder='Select a state')
)
This code does what I expect:
updateSelectizeInput(session, 'basic_selectizer',
server=TRUE,
label=NULL,
choices=paste(state.abb,state.name),
options=list(maxItems=3, placeholder='Select a state')
)
I would like to get the full power of render but can't seem to make it work. What am I doing wrong with the render version?

Summing rows on a tabular form in apex 4.2 for validation

How can I sum fields on each row in a tabular form in APEX 4.2 to get a total for that row before I submit the page in order to do page validation?
For example if the first row has 6 in field a and 6 in field b the total for the first row should be 12 and on the second row if field b is 5 and field c is 5 the total for the second row should be 10.
So I want to get totals based on rows not column. Is that possible?
Yes, its possible. If you know javascript/jquery, you'll get along well with my solution. This is what you have to do:
get the name attribute(using inspect element of your browser) of the field you want to sum up. Names of fields in oracle apex usually goes like 'f01' or 'f02' and so on. Once you get the fields, create a javascript function or you can use this one if you like:
function sumUpRows(columnforsum,itemstobeadded){
var numofcols = arguments.length;
var numofrows = $("[name=" + arguments[0] + "]").length;
var summ = 0;
for(x=0;x<numofrows;x++){
for(i=1;i<numofcols;i++){
summ = summ + Number($("[name=" + arguments[i] + "]").eq(x).val());
}
$("[name=" + columnforsum + "]").eq(x).val(summ);
}
}
Put function above in "function and global variable declaration" part of your page. Then create a "before page submit" dynamic action. Set its action to "execute javascript" then put this line of code:
sumUpRows("nameoffieldwheresumwillbeassigned","nameofitem1","nameofitem2","nameofitem3");
Here's a sample :
sumUpRows("f04","f01","f02","f03");
For your question in the comment section, the answer is yes. To get the sum of a row automatically as you fill up the boxes on that row, you can use this function:
function sumUpRowsAsYouGo(whatelement){
var numofrows=$("[name=f01]").length;
var summ = 0;
for(i=0;i<numofrows;i++){
if($(whatelement).attr("id") == $("[name=" + $(whatelement).attr("name") + "]").eq(i).attr("id")){
for(a=1;a<(arguments.length-1);a++){
summ += Number($("[name="+ arguments[a] + "]").eq(i).val());
}
$("[name="+ arguments[arguments.length-1] + "]").eq(i).val(summ);
break;
}
}
}
you can use this function like this(put these lines in the "Execute on Page load" and "after refresh" dynamic action of your tabular form region):
$("[name=f01]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);
$("[name=f02]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);
$("[name=f03]").change(function(){
sumUpRowsAsYouGo(this,"f01","f02","f03","f04");
}
);

Add a dynamic key to an anonymous List

How can I add a dynamic key to an anonymous List such as the mydatetime below:
DateTime myDateTime = DateTime.Parse(datepickerval, ukCulture.DateTimeFormat);
var qid = (from p in db.Vw_INTERACTPEOPLE
select p
);
var AvilList = new List<object>();
var ddate = myDateTime.DayOfWeek.ToString().Substring(0, 3) + "Jul" + myDateTime.Day;
foreach (var q in qid)
{
AvilList.Add(
new
{// Availability
Name = q.Fullname,
here >>> ddate = "Some Test"
});
As adam says above there is no way to do this using Lists, however since the Slickgrid is expecting a Json return, I simply built the string in .net then returned it via the JavaScriptSerializer serializer, then in the code behind simply used eval to de-serialize back into an array.