Saved search returns no results programmatically - c#

I have the following code:
var search = new TransactionSearchAdvanced();
search.savedSearchId = "680";
SearchResult searchResult = Client.Service.search(search);
var resultList = searchResult.searchRowList;
var castList = resultList.Cast<TransactionSearchRow>();
Everytime I call this method I get 0 search results returned. If I view the saved search in NetSuite itself I have over 1000 results.
I am running a similar search on customers that is 100% working.
public static List<Account> GetCustomerList()
{
var search = new CustomerSearchAdvanced();
search.savedSearchId = "678";
try
{
SearchResult searchResult = Client.Service.search(search);
var resultList = searchResult.searchRowList;
var castList = resultList.Cast<CustomerSearchRow>();
var accountList = new List<Account>();
foreach (var resultRow in castList)
{
var basic = resultRow.basic;
var account = new Account();
account.NsAccountId = basic.entityId?.FirstOrDefault()?.searchValue;
account.Name = basic.companyName?.FirstOrDefault()?.searchValue;
account.EmailAddress1 = basic.email?.FirstOrDefault()?.searchValue;
account.Address = basic.address?.FirstOrDefault()?.searchValue;
account.BillingAddress = basic.billAddress?.FirstOrDefault()?.searchValue;
account.Telephone1 = basic.phone?.FirstOrDefault()?.searchValue;
account.BillingPhone = basic.billPhone?.FirstOrDefault()?.searchValue;
account.Fax = basic.fax?.FirstOrDefault()?.searchValue;
account.WebAddress = basic.url?.FirstOrDefault()?.searchValue;
accountList.Add(account);
}
return accountList;
}
I have tried adding the the role to view transactions. I am totally unfamiliar with netsuite itself and have no idea what it could be since all the settings on my 2 searches are identical.
EDIT
The SearchResult objects are actually different:
looking into this now

In the saved search interface of NetSuite there is a field that needs to be chacked "Run Unrestricted" this is what solved it for me.

Related

Active Directory Query Users with contains ids from an array using C#

I am trying to perform a query to Active Directory to obtain all users where id is contained in the input array using a single query.
Is it possible? It
public List<Principal> Get(IEnumerable<string> ids)
{
var context = new PrincipalContext(ContextType.Domain);
var userPrincipal = new UserPrincipal(context)
{
// SOME logic with input array
};
var searcher = new PrincipalSearcher(userPrincipal);
return searcher.FindAll().ToList();
}
It is not a problem to query single user by id:
public static UserPrincipal? Get(string id)
{
var context = new PrincipalContext(ContextType.Domain);
var userPrincipal = UserPrincipal.FindByIdentity(context, id);
return userPrincipal;
}
Also, I can not find any information in docs
You can't do it with PrincipalSearcher. You'll have to use DirectorySearcher (which is what PrincipalSearcher uses behind the scenes anyway).
I actually already wrote a method that does exactly this in an article I wrote about getting better performance when programming withActive Directory. That method takes usernames and returns a list of email addresses:
public IEnumerable<string> GetEmailAddresses(IEnumerable<string> usernames) {
var filter = new StringBuilder();
var numUsernames = 0;
var e = usernames.GetEnumerator();
var hasMore = e.MoveNext();
while (hasMore) {
var username = e.Current;
filter.Append($"(sAMAccountName={username})");
numUsernames++;
hasMore = e.MoveNext();
if (numUsernames == 50 || !hasMore) {
var search = new DirectorySearcher(new DirectoryEntry()) {
PageSize = 1000,
Filter = $"(&(objectClass=user)(objectCategory=person)(|{filter}))"
};
search.PropertiesToLoad.Add("mail");
using (var results = search.FindAll()) {
foreach (SearchResult result in results) {
yield return (string) result.Properties["mail"][0];
}
}
filter.Clear();
numUsernames = 0;
}
}
}
This method builds an LDAP query in the format:
(&(objectClass=user)(objectCategory=person)(|(sAMAccountName={username1})(sAMAccountName={username2})))
It does them in batches of 50 just to make sure you never hit the size limit on LDAP requests, although you could probably push that number higher.
You can adapt it to return whatever you'd like by changing the method signature and the yield return line.
In that same article I discuss the benefits of using DirectoryEntry/DirectorySearcher instead of the AccountManagement namespace. You can get far better performance.

Rally .NET: Query for project admins that belong to a specific project?

I am looking for a List object that is populated with project admins for a specific project that is within a specific workspace.
Would like some sample code that can query the API for to retrieve all the project admins email addresses.
Here is some sample code I have tried.
public void getProjectAdmins(string workspaceRef, string projectRef)
{
this.EnsureRallyIsAuthenticated();
Request projectAdminRequest = new Request("User");
projectAdminRequest.Workspace = workspaceRef;
projectAdminRequest.Project = projectRef;
projectAdminRequest.ProjectScopeUp = RallyConstant.ProjectScopeUp;
projectAdminRequest.ProjectScopeDown = RallyConstant.ProjectScopeDown;
projectAdminRequest.Fetch = new List<string>()
{
"Admin", "Email"
};
try
{
//query the items in the list
projectAdminRequest.Query = new Query();
QueryResult result = _rallyRestApi.Query(projectAdminRequest);
//iterate through the result set
foreach (var admin in result.Results)
{
var adminResult = admin[RallyConstant.Owner];
if (adminResult != null)
{
var x = adminResult[RallyQueryConstant.ReferenceObject];
}
}
}
catch (WebException)
{
Console.WriteLine(RallyQueryConstant.WebExceptionMessage);
}
}
You should be able to query the ProjectPermission endpoint filtered to your project in question like so:
Request projectAdminRequest = new Request("ProjectPermission");
projectAdminRequest.Workspace = workspaceRef;
projectAdminRequest.Fetch = new List<string>() {"User", "EmailAddress"};
projectAdminRequest.Query = Query.And(
new Query("Project", Query.Operator.Equals, "/project/12345"),
new Query("Role", Query.Operator.Equals, "Project Admin"));
Fetching User and EmailAddress should include the data you're looking for in your request.

How to add/update milestones in a feature using rally rest API and C#?

I am not able to add or update milestones field for the Features in the Rally. If anyone having the code available using C# to update the same, please share with me. I am searching and doing from last one week with no luck.
When I am trying to add/Update milestones in the Features. I am getting the error as "Could not read: Could not read referenced object null". My code is as follows:-
public DynamicJsonObject UpdateFeaturesbyName(string fea, string bFun)
{
//getting list of Feature.
Request feat = new Request("PortfolioItem/Feature");
feat.Query = new Query("Name", Query.Operator.Equals, fea);
QueryResult TCSResults = restApi.Query(feat);
foreach (var res in TCSResults.Results)
{
var steps = res["Milestones"];
Request tsteps = new Request(steps);
QueryResult tstepsResults = restApi.Query(tsteps);
foreach (var item in tstepsResults.Results)
{
}
if (res.Name == fea)
{
var targetFeature = TCSResults.Results.FirstOrDefault();
DynamicJsonObject toUpdate = new DynamicJsonObject();
//toUpdate["Milestones"] = "";
// CreateResult createResult = restApi.Create(steps._ref, toUpdate);
// String contentRef = steps._ref;
//String contentRef = createResult._ref;
string[] value = null;
string AccCri = string.Empty;
if (!string.IsNullOrWhiteSpace(bFun))
{
value = bFun.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None);
foreach (string item in value)
{
//if (string.IsNullOrWhiteSpace(AccCri))
// AccCri = item;
//else
// AccCri = AccCri + "<br/>" + item;
if (!string.IsNullOrWhiteSpace(item))
{
//Query for Milestone.
Request ms = new Request("Milestone");
ms.Fetch = new List<string>() { "Name", "ObjectID" };
ms.Query = new Query("Name", Query.Operator.Equals, item);
QueryResult msResults = restApi.Query(ms);
var targetMLResult = msResults.Results.FirstOrDefault();
long MLOID = targetMLResult["ObjectID"];
DynamicJsonObject tarML = restApi.GetByReference("Milestone", MLOID, "Name", "_ref", "DisplayColor");
DynamicJsonObject targetML = new DynamicJsonObject();
targetML["Name"] = tarML["Name"];
//targetML["_ref"] = tarML["_ref"];
targetML["_ref"] = "/milestone/" + Convert.ToString(MLOID);
targetML["DisplayColor"] = tarML["DisplayColor"];
// Grab collection of existing Milestones.
var existingMilestones = targetFeature["Milestones"];
long targetOID = targetFeature["ObjectID"];
// Milestones collection on object is expected to be a System.Collections.ArrayList.
var targetMLArray = existingMilestones;
var tagList2 = targetMLArray["_tagsNameArray"];
tagList2.Add(targetML);//
//targetMLArray.Add(targetML);
targetMLArray["_tagsNameArray"] = tagList2;
toUpdate["Milestones"] = targetMLArray;
OperationResult updateResult = restApi.Update(res._ref, toUpdate);
bool resp = updateResult.Success;
}
}
}
//toUpdate["c_AcceptanceCriteria"] = AccCri;
//OperationResult updateResult = restApi.Update(res._ref, toUpdate);
}
}
var features = TCSResults.Results.Where(p => p.Name == fea).FirstOrDefault();
var featuresref = features._ref;
return features;
}
Now that v3.1.1 of the toolkit has been released you can use the AddToCollection method to do this.
Otherwise, you can still always just update the full collection. The value should be an arraylist of objects with _ref properties.
Check out this example (which adds tasks to defects, but should be very similar to what you're doing): https://github.com/RallyCommunity/rally-dot-net-rest-apps/blob/master/UpdateTaskCollectionOnDefect/addTaskOnDefect.cs

How can I search 10 OUs in parallel using DirectoryServices

I need to query LDAP on multiple paths and I wish to use DirectoryServices for various reasons.
var ADobjects = new Dictionary<string, ADobject>();
foreach (var OUItem in OUs)
{
using (DirectoryEntry ldap = new DirectoryEntry("LDAP://" + OUItem))
{
using (DirectorySearcher searcher = new DirectorySearcher(ldap))
{
searcher.Filter = "(objectClass=user)";
searcher.PropertiesToLoad.Add("distinguishedName");
searcher.PropertiesToLoad.Add("cn");
searcher.PropertiesToLoad.Add("displayName");
using (SearchResultCollection results = searcher.FindAll())
{
foreach (SearchResult result in results)
{
var dn = result.Properties["distinguishedName"][0].ToString();
if (!ADobjects.ContainsKey(dn))
{
ADobjects.Add(dn, new ADobject(result));
}
}
}
}
}
}
This works.. but when I have 10 OU's to query I would like to launch these queries in parallel.
I know how to launch an async method (more or less) but how can I use these queries to fill 1 dictionary at the same time??
I've clicked around but I'm really unsure if this can and should be done async. Since every search might take a few seconds, it could really benefit from async tasks.
You can use futures http://msdn.microsoft.com/en-us/library/ff963556.aspx
example from mentioned source:
int BufferSize = ...
var buffer1 = new BlockingCollection<string>(BufferSize);
var f = new TaskFactory(TaskCreationOptions.LongRunning,
TaskContinuationOptions.None);
var stage1 = f.StartNew(() => LdapSearch(buffer1));
var stage2 = f.StartNew(() => LdapSearch(buffer1));
var stage3 = f.StartNew(() => LdapSearch(buffer1));
var stage4 = f.StartNew(() => LdapSearch(buffer1));
Task.WaitAll(stage1, stage2, stage3, stage4);
static void LdapSearch(BlockingCollection<string> output,
)
{
output.Add(some result);
}

MailChimp MCAPI.NET - Subscription Groupings

I'm interfacing with MailChimp using MCAPI.NET and I need to specify the groupings for subscriptions.
string emailAddr = "somebody#somewhere.net";
MailChimp.MCApi mc = new MailChimp.MCApi("myapikey", true);
var merges = new MailChimp.Types.List.Merges();
merges.Add("FNAME", "MyFirstName");
merges.Add("LNAME", "MyLastName");
var group = new string[]{"PSS"};
var grp = new MailChimp.Types.List.Grouping("Staff Type", group);
merges.Add("Groupings", grp);
mc.ListSubscribe("mylistid", emailAddr, merges);
My grouping isn't getting set. Does someone have a working example they could share?
The problem with your code is that you are not adding a list of groupings to the merge var "Groupings". The value has to be of the following type:
MailChimp.Types.MCList<MailChimp.Types.List.Grouping>
Here is a working copy:
var merges = new List.Merges();
var groupingList = new MailChimp.Types.MCList<MailChimp.Types.List.Grouping>();
var grouping = new MailChimp.Types.List.Grouping(myGroupId, new string[] { group1, group2 });
groupingList.Add(grouping);
merges["Groupings"] = groupingList;
// You may find it practical to include the following options, at least while testing the groupings
var options = new MailChimp.Types.List.SubscribeOptions();
options.DoubleOptIn = false;
options.ReplaceInterests = false;
options.SendWelcome = false;
mcapi.ListSubscribe(myMailChimpListId, email, merges, options);

Categories