I am looking for a way how to export sharepoint groups via javascript of specific user(filled via input box). Can someone advise please? I managed to export all groups on sharepoint as well as currently logged in but not specific one. I also found the basics on microsoft web but there is nothing about specific user.
Is it somehow possible via REST?
Thank you
So I managed to do it with this functions if anyone is interested.
function GetMembersOfGroup(grpName){
$.ajax({
url: _spPageContextInfo.webAbsoluteUrl + "/_api/web/sitegroups/getByName('"+ grpName +"')/users",
type: "GET",
headers: {"accept": "application/json;odata=verbose"},
success: function (data){
if (data.d.results)
{
for (var i = 0; i < data.d.results.length; i++) {
//Loop through all users and binding in dropdown
if (data.d.results[i] != null && data.d.results[i] != undefined) {
if (data.d.results[i].LoginName == "i:0#.w|ad\\" + document.getElementById("userCkToRemove").value.toLowerCase()) {
if ($("#groupNameToRemove option[value='" + data.d.results[i] + "‘]").length == 0) {
$('#groupNameToRemove').append($("<option/>", {
value: data.d.results[i].Email,
text: grpName
}));
}
}
}
}
}
},
error: function (error) {
alert(JSON.stringify(error));
}
});
}
This functions exports all members and checks whether the login name of export "file" equals the login name that we want to search (coming from input box in html). If yes then we add the name of the group in the drop-down tag based on id #groupNameToRemove which is select tag and I create and option tag within it per each group that the user is member
Related
I'm working on a queue management page where we have multiple Html tables on a single page and each table holds 10 values including name and image, now I wanna remove a row from the table when the present button is pressed and I did it using this following code
function removePresent() {
const urlParams = new URLSearchParams(window.location.search);
const HallNo = urlParams.get('hallno');
const TvIP = urlParams.get('tvip');
$.ajax({
url: '#Url.Action("PresentDisplayRemover")',
type: "GET",
data: { 'HallNo': HallNo, 'TvIP': TvIP },
contentType: "application/json",
success: function (response) {
$.each(response, function (j, e) {
const rows = Array.from(document.getElementsByTagName('TD'));
$.each(rows, function (i) {
if ($(rows[i]).text() === e.StudentId) {
$(rows[i]).parent().remove();
}
});
}
});
}
Now my flow also requires me to find the Id of the matched to increment a counter, I have no idea how to do it and I also tried searching online but I ended up finding nothing,I'm relatively new to js and jquery since my main workflow only consists of me working with .NET so any help would be great, Thank You.
I can best explain my problem by showing the code first. I am working on a project with my friend (Rent a car project), so the code isn't completely mine. I searched (and used) some of the answers i found on similar questions, but none solved my problem. All of the pages here will be used by administrator.
1st
client_requests.php
This page contains javascript function called sureToApprove with which i have a problem : in the url the car variable is undefined (&car=undefined), while id has a value (it works). Also, this page contains some of the data from database.
<script type="text/javascript">
function sureToApprove(id, car) {
if (confirm("Da li ste sigurni?")) {
window.location.href = "approve.php?id=" + id + "&car=" + car;
}
}
function deleteRequest(id){
if (confirm("Da li ste sigurni?")) {
window.location.href = 'delete_request.php?id=' + id;
}
}
</script>
<script>
$(document).ready(function () {
load_data();
function load_data(query) {
$.ajax({
url: "fetch_requests.php",
method: "POST",
data: { query: query },
success: function (data) {
$('#result').html(data);
}
});
}
$('#search_text').keyup(function () {
var search = $(this).val();
if (search != '') {
load_data(search);
}
else {
load_data();
}
});
});
</script>
2nd page is fetch_requests.php which contains a query which will be shown on 1st page (client_requests.php). Query and the rest of the code works perfectly.
<tr>
<td>'.$row["fname"].'</td>
<td>'.$row["lname"].'</td>
<td>'.$row["email"].'</td>
<td>'.$row["phone"].'</td>
<td>'.$row["car_name"].'</td>
<td>'.$row["mpesa"].'</td>
<td>'.$row["status"].'</td>
<td>
Izbriši
Approve
</td>
</tr>
When the link approve is clicked, it redirects to 3rd page (approve.php) in which the data in database is regulated. The url looks something like this
http://localhost/Rent-a-car/admin/approve.php?id=7&car=undefined
I need the car variable for regulating the database, and i can't find out why it is not picking up the value instead is undefined. Thank you in advance.
Im working on a simple app, that allow the user to login. Im using an ajax function pass the values to a PHP file(on a different domain). If the user and the password are correct the page display echo"success" and im using that word to validate and create a random key to allow the user access to a private page.
I was reading that you can also add a header token, it is possible to add that to my current code..
Iam new in developing "app", hope some one can point in the right direction on what is the best way to do this.
var username = $("#username").val();
var password = $("#pass").val();
var dataString = "username="+username+"&pass="+password+"&insert=";
$.ajax({
type: "POST",
url: "url",
data: dataString,
crossDomain: true,
cache: false,
beforeSend: function() {$('#loginButton').val('Connecting...');},
success: function(data)
{
if(data == " success")
{
alert("Success");
returnHash();
}
if(data == " Login failed")
{
alert("There's a problem with username/password!");
$('#loginButton').val('Submit');
}
}
});
function returnHash()
{
letters = "abcdefghijklmnopqrstuvwxyz1234567890".split("");
window.token="";
for(i=0;i<64;i++){
window.token += letters[Math.floor(Math.random()*letters.length)];
}
success();
}
To create a real unique hash, use the current time with an random generated number like in the code below:
var dateForHash = (new Date()).valueOf().toString();
var createRandomNum = Math.random().toString();
crypto.createHash('sha1').update(dateForHash + createRandomNum).digest('hex');
You can also use crypto.randomBytes()- this hash is practical unique but not theoretical.
var hash = crypto.randomBytes(20).toString('hex');
I would recommend the second way for this type of use.
I have a form and a jQuery function which is triggered if user changes a html select field. The function collects all of the information what it needs and posts to a php script with an ajax post.
I want to extend this function with a new feature: if the selected value equals to a predefined value I want to display a dialog with two buttons. The user needs to click one of these buttons and if he does the new information will attached to the post.
An easy example:
The select has 3 options:
- Lemon
- Banana
- Apple
If the user selects lemon or banana, the scripts sends the info to the server without further actions. But if he selects apple, I need an extra dialog, because I want to ask if he needs a red or a green one. And it needs to be attached to the information which I want to send to the server.
Could you help me guys how should I do it?
I have only the first part:
$('select.myList').change( function()
{
var e = $(this)
var val = $(this).val();
var id = $(this).attr('data-id')
var url = 'index.php?process'
$.ajax({
type: "POST",
url: url,
data: { id: id, val: val },
success: function(data){
var o = $.parseJSON(data);
if( o.error )
{
console.log('error:' + o.message);
} else
{
console.log('success:' + o.message);
}
return false;
}
})
return false
})
First, I would say you should be extremely careful with your variable names. You should NEVER use e as a variable if it can be avoided. I would also change id and val.
In any case you should be able to use the beforeSend property in ajax: http://api.jquery.com/jquery.ajax/, so assuming that 'apple' would be the val of the element:
$.ajax({
type: "POST",
url: url,
data: { id: id, val: val },
beforeSend: function() {
if (val === 'Apple') {
//do stuff
}
},
// rest of ajax call
}
I have created a custom entity called Alert. I have associated this with the out of the box Account entity.
What I want to do now is to customise the Account form so that when a user opens it, it checks if the current account has any active alerts. If it does, it should show a message informing them of this (a javascript alert?) and then navigate to the alerts view for the account.
I've done some basic javascript in CRM but I'm not sure how to query related entities.
Note Active alert is defined by the Display From and Display Until dates in the Alert being active dates (Display From <= Today AND Display Until >= Today).
Update
Thanks for pointing me in the direction of oData. I now have the following function which is looking up the account set but expanding the relationship with the alerts. I'm trying to figure out how to check if there are any alerts, currently my code always triggers the javascript alert.
function CheckForAlerts(accountId)
{
var odataSelect = "http://mscrmdev/Test/xrmservices/2011/OrganizationData.svc/AccountSet?$expand=new_account_new_alert_Account&$filter=AccountNumber eq '" + accountId + "'";
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: odataSelect,
beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json"); },
success: function (data, textStatus, XmlHttpRequest)
{
// Use only one of these two methods
// Use for a selection that may return multiple entities
ProcessReturnedEntities(data.d.results);
},
error: function (XmlHttpRequest, textStatus, errorThrown) { alert('OData Select Failed: ' + odataSelect); }
});
}
function ProcessReturnedEntities(ManyEntities)
{
var oneEntity = ManyEntities[0];
if (oneEntity != null)
{
alert('There are active alerts associated with this account.');
}
}
The best way to do this will be via an oData query from the javascript. The CRM 2011 SDK comes with some helper functions for oData calls like this. You will want to use the 'retrieveMultiple' method which will allow you to retrieve all 'alerts' with a lookup to the 'account' in question.
First add the 'RESTJQueryEditor.js' file from the SDK to your form and then you can add your own custom script to perform the retrieve. I then suggest creating the message which you wish to show the user in the callback success function, something like the following:-
retrieveMultiple('nameOfYourAlertEntitySet', '?$filter=myAccountLookupName eq ' + accountId, function(alerts){
if(alerts.length > 0)
{
var message = '';
for(var index = 0; index<alerts.length; index++)
{
message += 'alert: ' + alerts[index].name;
}
alert('Found associated alerts: ' + message);
}
else
{
alert('No associated alerts found for this account');
}
},
function(){
// Log an exception
});
You will want to make the alert message a little nicer of course and adjust your attribute names accordingly, but this is the flavour of what you want to do I believe. Additionally, you can add any further criteria on the alert entity in the filter by use of the 'and' keyword.
Let me know if you have any issues.