Queried parameter is null - reactjs

I'm trying to query the pid parameter of my http://localhost:3000/edit-product?pid=Z4HLrHGZ1ikKIwlEVkM6 URL.
Here is my code:
const params = new URLSearchParams(window.location.path);
const pid = params.get("pid");
console.log("This----->", pid);
Each time I run the code, the console prints that the pid value is null
Any ideas what I'm doing wrong?

You should be using window.location.search. window.location.path is undefined.
MDN: URLSearchParams#Examples
Gotchas
The URLSearchParams constructor does not parse full URLs.
However, it will strip an initial leading ? off of a string, if
present.
var paramsString1 = "http://example.com/search?query=%40";
var searchParams1 = new URLSearchParams(paramsString1);
searchParams1.has("query"); // false
searchParams1.has("http://example.com/search?query"); // true
searchParams1.get("query"); // null
searchParams1.get("http://example.com/search?query"); // "#" (equivalent to decodeURIComponent('%40'))
var paramsString2 = "?query=value";
var searchParams2 = new URLSearchParams(paramsString2);
searchParams2.has("query"); // true
var url = new URL("http://example.com/search?query=%40");
var searchParams3 = new URLSearchParams(url.search);
searchParams3.has("query") // true

Related

React-URLSearchParams returning Null object

I am using the following code to retrieve query parameters from URL but URLSearchParams returns an empty object.
PS: uselocation.search returning correct output.
const stringdata = useLocation().search
const queryparameter = new URLSearchParams(stringdata)
console.log("query parameter :", queryparameter)
const query = queryparameter.get('q');
var url_string = `http://localhost:3000/recipes${query}`
You can try using window.location.search over user search params.
That should look something like:
const queryParams = new URLSearchParams(window.location.search);
const query = queryParams.get('q');
let url_string = `http://localhost:3000/recipes${query}`;
The search property returns the querystring part of a URL, including the question mark (?).
const queryParams = new URLSearchParams(window.location.search);
Then you need to check if queryparameter.get('q') exists, otherwise it will return null and will append null to url.
let query;
if(queryParameter.has('q')){
query = queryparameter.get('q');
}
then
var url_string = `http://localhost:3000/recipes/${query}`

Validation xpages file download control

I have to do a validation in component file download Control, checking if any file is listed. Does anyone know how to do this validating. How can I get the object representing the xpages component and list the files by any of its methods?
here is some code I use to get hold on the upload via ssjs (if you want that)
var con = facesContext.getExternalContext();
var request:com.sun.faces.context.MyHttpServletRequestWrapper = con.getRequest();
var fileDataName = getClientId('ctrlUpload') ;
var map:java.util.Map = request.getParameterMap();
var fileData:com.ibm.xsp.http.UploadedFile = map.get(fileDataName);
if( fileData == null ){
growl.createGrowlMessage("<strong>Warning</strong> no file to upload selected","danger");
return;
}
var tempClientFile = fileData.getClientFileName();
var tempFile:java.io.File = fileData.getServerFile();
var filePath = tempFile.getParentFile().getAbsolutePath();
var correctedFile = new java.io.File(filePath+java.io.File.separator + tempClientFile );
var success = tempFile.renameTo(correctedFile);
var doc:NotesDocument = attachDoc.getDocument(true);
var rtFiles:NotesRichTextItem = null;
if(!(doc.hasItem("Files"))){
rtFiles = doc.createRichTextItem("Files");
}else{
rtFiles = doc.getFirstItem("Files");
}
rtFiles.embedObject(lotus.domino.local.EmbeddedObject.EMBED_ATTACHMENT,"",correctedFile.getAbsolutePath(), null);
correctedFile.renameTo(tempFile);
attachDoc is the reference to the data-binding I have set up:
<xp:this.data>
<xp:dominoDocument formName="fa_Attachment"
var="attachDoc">
</xp:dominoDocument>
</xp:this.data>

Want to retrieve values not other details from array object in rally

Want to retrieve below values from array object not other details, but getting whole data like events, listeners, etc.
2014-10-01: 02014-10-02: 02014-10-06: 42014-10-08: 50.2857142857142852014-10-09: 42014-10-10: 32014-10-13: 32014-10-14: 2.52014-10-15: 52014-10-16: 02014-10-20: 32014-10-21: 12014-10-27: 32014-10-28: 6.7777777777777782014-10-29: 12014-10-31: 0.66666666666666662014-11-03: 42014-11-04: 19.252014-11-05: 33.62014-11-06: 12014-11-07: 32014-11-10: 32014-11-11: 3.6666666666666665
Below is my some of the code which generate this object, any help on this please..
var daysOfMonth = new Ext.util.HashMap();
//console.log("startdate", this.startDate);
//console.log("enddate", this.endDate);
start = new Date(this.startDate);
end = new Date(this.endDate);
for (start; start <= end; start.setDate(start.getDate() + 1)) {
daysOfMonth.add(new Date(start), null);
}
//daysOfMonth = Ext.Array.flatten(daysOfMonth);
console.log("days of month", daysOfMonth);
var userstory_cycle_times_by_date = this._getCycleTimes(userstory_snaps_by_date);
var storydaysOfMonth = Ext.Object.merge(daysOfMonth, userstory_cycle_times_by_date);
//console.log("days of month", daysOfMonth);
var defect_cycle_times_by_date = this._getCycleTimes(defect_snaps_by_date);
var defectdaysOfMonth = Ext.Object.merge(daysOfMonth, defect_cycle_times_by_date);
You can get an object of all the key/value pairs like so:
_.reduce(daysOfMonth.getKeys(), function(result, key) {
result[key] = daysOfMonth.get(key);
return result;
}, {});
I'm curious why you're using a HashMap to begin with rather than just a regular plain old javascript object literal?

Initializing a NotificationController in DNN 7

How do you initialize a NotificationController in DNN 7.1.2?
I've tried:
var nc = new DotNetNuke.Services.Social.Notifications.NotificationController();
However this is empty and has no methods to call... Am I initializing the wrong thing?
Surely there should be something in there other than ToString, GetType, Equals and GetHashCode
I need to be able to create NotificationTypes and create Notifications.
Thanks
You can use NotificationsController.Instance.SendNotification method to send notifications.
Here is the example:
var notificationType = NotificationsController.Instance.GetNotificationType("HtmlNotification");
var portalSettings = PortalController.GetCurrentPortalSettings();
var sender = UserController.GetUserById(portalSettings.PortalId, portalSettings.AdministratorId);
var notification = new Notification {NotificationTypeID = notificationType.NotificationTypeId, Subject = subject, Body = body, IncludeDismissAction = true, SenderUserID = sender.UserID};
NotificationsController.Instance.SendNotification(notification, portalSettings.PortalId, null, new List<UserInfo> { user });
This will send notification to a specific user.
If you need to create your own Notification type use the code below as a guide, it will create a NotificationType "GroupApprovedNotification". This is from core groups module.
type = new NotificationType { Name = "GroupApprovedNotification", Description = "Group Approved Notification", DesktopModuleId = deskModuleId };
if (NotificationsController.Instance.GetNotificationType(type.Name) == null)
{
NotificationsController.Instance.CreateNotificationType(type);
}

url sharepoint list camlquery

I'm trying to collect my url and the description of the url stored in a column of a list from sharepoint and i don't know how to collect the URL value.
This is my code :
var queryResultSaleListItems = clientContext.LoadQuery(listData);
clientContext.ExecuteQuery();
//Read the Data into the Object
var TipsList = from Tips in queryResultSaleListItems
select Tips;
ObservableCollection<Tips> colTips = new ObservableCollection<Tips>();
//Read Every List Item and Display Data into the DataGrid
foreach (SPSClient.ListItem item in TipsList)
{
var tips = new Tips();
tips.TitleTip = item.FieldValues.Values.ElementAt(1).ToString();
tips.App = item.FieldValues.Values.ElementAt(4).ToString();
//should collect the url
tips.URL = item.FieldValues.Values.ElementAt(5).ToString();
//should collect the description of the url
tips.URLdesc = item.FieldValues.Values.ElementAt(5).ToString();
colTips.Add(tips);
}
ListboxTips.DataContext = colTips;
In my expression its >
((Microsoft.SharePoint.Client.FieldUrlValue)(item.FieldValues.Values.ElementAt(5))).Url
((Microsoft.SharePoint.Client.FieldUrlValue)(item.FieldValues.Values.ElementAt(5))).Description
Thanks for your help,
Use FieldUrlValue for getting hyperlink field in Client Object Model.
Use Following Code:
string server = "siteURL";
var ctx = new ClientContext(server);
var web = ctx.Web;
var list = web.Lists.GetByTitle("CustomList");
var listItemCollection = list.GetItems(CamlQuery.CreateAllItemsQuery());
ctx.Load(listItemCollection);
ctx.ExecuteQuery();
foreach (Microsoft.SharePoint.Client.ListItem listItem in listItemCollection)
{
string acturlURL = ((FieldUrlValue)(listItem["URL"])).Url.ToString(); // get the Hyperlink field URL value
string actdesc = ((FieldUrlValue)(listItem["URL"])).Description.ToString(); // get the Hyperlink field Description value
}

Resources