Retrieve NGUCID from Rally - javascript

I am trying to retrieve custom NGUCID field from Rally but when I try to display it I get a value of "undefined". I have tried a few different options such as changing the type to PortfolioItem and Artifact. But it seems to me that the main issue is happening when I am dereferencing the object.
Here's my code:
function defectsExample() {
var displayDefects = function(results) {
var defectsInfo = "";
var defect = "";
var num;
var swpCounter = 0;
var storyCounter = 0;
var re = new RegExp('SWP');
for (i=0 ; i < results.defects.length ; i++) {
defect = results.defects[i];
storyCounter++;
// if ((re.test(defect.Name)) == true) {
defectsInfo += defect.Name + '<br>' + defect.NGUCID;
swpCounter++;
// }
}
var aDiv = document.getElementById("aDiv");
// aDiv.innerHTML = '<strong>Name, State, Severity</strong><br/>';
defectsInfo += 'Number of SWP stories: ' + swpCounter + '<br>';
defectsInfo += 'Total number stories: ' + storyCounter + '<br>';
aDiv.innerHTML += defectsInfo;
};
var queryConfig = {
/* type : 'HierarchicalRequirement',
key : 'defects',
query: '((Iteration.Name = "Sprint 40") AND ((Project.Name contains "CRM") OR (Project.Name contains "AR")))',
fetch: true //'Name, AcceptedDate'*/
type : 'HierarchicalRequirement',
key : 'defects',
// query: '(Iteration.Name = "Sprint 39")',
//query: '(NGUCID contains "1")',
fetch: 'Name,FormattedID,Project,NGUCID'
};
var rallyDataSource = new rally.sdk.data.RallyDataSource('__WORKSPACE_OID__',
'__PROJECT_OID__',
'__PROJECT_SCOPING_UP__',
'__PROJECT_SCOPING_DOWN__');
rallyDataSource.findAll(queryConfig, displayDefects);
}
rally.addOnLoad(defectsExample);

NGUCID is not a standard Rally field, so I assume it is one that you, or your organisation, have added as a Custom Field on the defect artefact type. All custom fields are accessible if the name is prefixed with 'c_'. In your case, it might be that you need to use "defect.c_NGUCID"
If you go to the WSAPI docs (https://rally1.rallydev.com/slm/doc/webservice/) it will show you the field names available to you for the various artefact types.

Related

Cannot read property 'split' of null

I cannot display all the results because on the following channel there is no image and therefore I have the following message
$.get('https://wcf.tourinsoft.com/Syndication/3.0/cdt33/c616ab2a-1083-4ba0-b8e2-f7741e443e46/Objects?$format=json', function(data) {
//$.get('/json/ecranv2.json', function(data){
var blogs = data.value;
$(blogs).each(function() {
var manifs = this.Listingraisonsociale;
var ouverturecomp = this.Listinginformationsouverture;
var commune = this.Listingcommune;
var ouverture = this.Listingouverture;
var photos = this.Listingphotos;
//var datatest= this.Listingphotos;
let output = '';
let users = this.Listingphotos.split('$');
//var testsplit = split($);
for (var i = 0; i < users.length; i++) {
console.log(users[i]);
output += '<img src=' + users[i] + '?width=150&height=150&crop=1>';
}
$('.target').append('<p>' + manifs + '</p><span>' + output + '</span>');
});
});
The one index does not have a value for the property. It is null, so you need to check to see if it is null before you try to use split on it. A simple truthy check will work in this case.
let users = this.Listingphotos ? this.Listingphotos.split('$') : [];
With it in place:
$.get('https://wcf.tourinsoft.com/Syndication/3.0/cdt33/c616ab2a-1083-4ba0-b8e2-f7741e443e46/Objects?$format=json', function(data) {
//$.get('/json/ecranv2.json', function(data){
var blogs = data.value;
$(blogs).each(function() {
console.log(this);
var manifs = this.Listingraisonsociale;
var ouverturecomp = this.Listinginformationsouverture;
var commune = this.Listingcommune;
var ouverture = this.Listingouverture;
var photos = this.Listingphotos;
//var datatest= this.Listingphotos;
let output = '';
let users = this.Listingphotos ? this.Listingphotos.split('$') : [];
//var testsplit = split($);
for (var i = 0; i < users.length; i++) {
console.log(users[i]);
output += '<img src=' + users[i] + '?width=150&height=150&crop=1>';
}
$('.target').append('<p>' + manifs + '</p><span>' + output + '</span>');
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="target"></div>
split is a method on string objects, which will be called on an actual string's reference.
So in your case, the split is not being called on a string, and the error message clearly states that we are using split over a null object. So make sure the object you are working on is an actual string, and work on it accordingly.
split mdn

Netsuite - on creation of a record using webservices cannot add new line item to database

On creation of a Netsuite record, I'm attempting to add a description line item to the sublist of the record.
I have tried to trigger the script that is adding the line item on before record submit and after record submit.
The script is firing yet the nlapiInsertLineItem function is not inserting a line.
It works perfectly on on 'edit', but for some reason not on 'create'.
Does anyone have experience inserting a new line item on creation of a record in Netsuite?
I should mention this record is being created by webservices.
Thanks for your help!
My code currently as is:
function optiv_SFquote_visibility_AS(type){
if(type == 'create'){
var recId = nlapiGetRecordId();
var recType = nlapiGetRecordType();
var rec = nlapiLoadRecord(recType, recId);
var itemCnt = rec.getLineItemCount('item');
var soVals = {};
var j = 0;
for(var i = 1; i <= itemCnt+j; i ++){
var grpNum = rec.getLineItemValue('item', 'custcol_grp_num', i);
if(isNotNull(grpNum) && soVals[grpNum] == undefined){
soVals[grpNum] = grpNum;
j++;
var grpDscrpt = rec.getLineItemValue('item', 'custcol_sf_quote_dscrpt', i);
var grpName = rec.getLineItemValue('item', 'custcol_grp_sf_name', i);
nlapiLogExecution('DEBUG', 'group description', grpDscrpt + ' name ' + grpName);
var newDscrpt = '';
if(isNotNull(grpDscrpt) && isNotNull(grpName)){
var newDscrpt = grpName + ' - ' + grpDscrpt;
}
else if(isNotNull(grpName) && isNull(grpDscrpt)){
var newDscrpt = grpName;
}
rec.insertLineItem('item', i);
rec.setLineItemValue('item', 'item', i, -3);
rec.setLineItemValue('item', 'description', i, newDscrpt);
}
}
nlapiSubmitRecord(rec);
}
}
We have an similar situation where we add a line item to a sales order if it contains a value in a specific field. It is executing on beforeSubmit when a sales order is created. We're not using the full nlapiInsertLineItem() function, but the insertLineItem() function that can be found on nlobjRecord.
function addFreightLine(freightInstructions) {
var record = nlapiGetNewRecord();
var newLineNum = record.getLineItemCount('item') + 1;
record.insertLineItem('item', newLineNum);
record.setLineItemValue('item', 'item', newLineNum, 733); // 733 is the 'CF' item
record.setLineItemValue('item', 'description', newLineNum, freightInstructions);
record.setLineItemValue('item', 'rate', newLineNum, 0);
}

JSON input string error using $.ajax

My web API accepts below JSON format (this is input parameter)
[{
"atrSpaUserId": "47fe8af8-0435-401e-9ac2-1586c8d169fe",
"atrSpaClassLegendId": "00D18EECC47E7DF44200011302",
"atrSpaCityDistrictId": "144d0d78-c8eb-48a7-9afb-fceddd55622c"},
{
"atrSpaUserId": "47fe8af8-0435-401e-9ac2-1586c8d169fe",
"atrSpaClassLegendId": "00D18EECC47E7DF44200011302",
"atrSpaCityDistrictId": "144d0d78-c8eb-48a7-9afb-fceddd55622c"
}
]
I am building request below in javascript.
var administratorId = '47fe8af8-0435-401e-9ac2-1586c8d169fe'
var districtId = '144d0d78-c8eb-48a7-9afb-fceddd55622c'
var atrUserLegendsInputs
for (i = 0; i < list.get_items().get_count() ; i++)
{
atrUserLegendsInputs += { atrSpaUserId: administratorId, atrSpaClassLegendId: list.getItem(i).get_value(), atrSpaCityDistrictId: districtId } + ',';
}
atrUserLegendsInputs = atrUserLegendsInputs.substring(0, atrUserLegendsInputs.length - 1);
var legendIds = '[' + atrUserLegendsInputs + ']';
var atrDistrictLegend = { districtID: cityDistrictId, legendIDs: legendIds };
var test = JSON.stringify(atrDistrictLegend);
getting error message:
{["The input was not valid."]}
I am not sure whether I am doing the right way. I am new to Json and ajax calls. Can you one please help me to fix this issue
Try this code
var administratorId = '47fe8af8-0435-401e-9ac2-1586c8d169fe';
var districtId = '144d0d78-c8eb-48a7-9afb-fceddd55622c';
//* create empty array for legends
var atrUserLegendsInputs = [];
for (i = 0; i < list.get_items().get_count() ; i++) {
//* put some values into legends' array
atrUserLegendsInputs.push({
atrSpaUserId: administratorId,
atrSpaClassLegendId: list.getItem(i).get_value(),
atrSpaCityDistrictId: districtId
});
}
var atrDistrictLegend = {
districtID: cityDistrictId,
legendIDs: atrUserLegendsInputs
};
var test = JSON.stringify(atrDistrictLegend);

Need some help on logic (Xpages : Javascript) To get update Candidate No by Add on 1 if found item

View itself is sorted by decending order!(First column is "New_Exam_No")
currentExamNo = doc.getItemValueString("New_Exam_No");
var Candvw:NotesView = database.getView("(Exam Application Subject Sort by ExamNo)");
var CandEntry:NotesViewEntry=Candvw.getEntryByKey(doc.getItemValueString("New_Exam_No"),true);
if (CandEntry!=null) //If have exam no, use this condition
{
var CandDoc = CandEntry.getDocument()
if (Canddoc.hasItem("Candidate_No")==true) // assign Candidate No yet?Yes!
{
var CandNo = Canddoc.getItemValueString("Candidate_No");
LCandNo = "LSBS"
MidCandNo = #Left(CandNo,7)
MCandNo = #TextToNumber(#Right(MidCandNo,2)) + 1;
CNo = #Right("00"+#Text(MCandNo),2);
RExamNo = currentExamNo;
CandidateNo = LCandNo + "/" + CNo + "/" +RExamNo ;
}
else
{
CandidateNo = "LSBS/01/" + currentExamNo;
}
}
else
{
CandidateNo = "LSBS/01/" + currentExamNo;
}
Why i always get the LSBS/01/examno as it doesn't add on 1.
getEntryByKey() takes a Vector rather than a String. Try:
var key:java.util.Vector = new java.util.Vector();
key.add(doc.getItemValueString("New_Exam_No"));
var CandEntry:NotesViewEntry=Candvw.getEntryByKey(key,true);
It's been a while since I used SSJS, but I think that should work.

TypeError: Cannot read property "0" from undefined - Javascript

I am trying to run the following code and I am getting the following error:
TypeError: Cannot read property "0" from undefined. (line 111)
The line in question would be:
perCampaignRows.push([STRATEGISTS[i][1],
and here's the full code.
var perCampaignRows = [];
for (var i = 0; i < STRATEGISTS.length; i++) {
var accountIterator = MccApp.accounts()
.withCondition("ManagerCustomerId = '" + STRATEGISTS[i][0] + "'")
.get();
var mccAccount = AdWordsApp.currentAccount();
while (accountIterator.hasNext()) {
var account = accountIterator.next();
MccApp.select(account);
Logger.log("Checking " + account.getName() + " - CID: " + account.getCustomerId());
var campaignIterator = AdWordsApp.campaigns()
.withCondition("Status = ENABLED")
.get();
var activeCampaigns = campaignIterator.totalNumEntities();
if (activeCampaigns === 0) {
Logger.log("No Active Campaigns");
perCampaignRows.push([
STRATEGISTS[i][1],
STRATEGISTS[i][2],
account.getCustomerId(),
account.getName(),
activeCampaigns,
'',
'',
'',
'',
'',
'',
'',
'',
'',
'',
]);
}
else {
Logger.log(activeCampaigns + " Active Campaigns");
}
while (campaignIterator.hasNext()) {
var campaign = campaignIterator.next();
Logger.log("Campaign: " + campaign.getName());
var mobileBid = checkPlatform(campaign);
var isRotatingEvenly = checkAdRotation(campaign);
var sitelinkData = checkSitelinks (campaign);
var isUsingMobileAds = checkAds(campaign);
var callExtData = checkCallExtensions(campaign);
var isUsingAdSchedule = checkAdSchedules(campaign);
var isSomewhatLimitedByBudget = checkBudgetLimitations(campaign);
if (isUsingAdSchedule && isSomewhatLimitedByBudget) {
var warnAboutBudgetAndSchedule = "TRUE";
}
else {
var warnAboutBudgetAndSchedule = "FALSE";
}
Logger.log(perCampaignRows);
perCampaignRows.push([
STRATEGISTS[i][1],
STRATEGISTS[i][2],
account.getCustomerId(),
account.getName(),
activeCampaigns,
campaign.getName(),
mobileBid,
isRotatingEvenly,
sitelinkData[0],
sitelinkData[1],
sitelinkData[2],
isUsingMobileAds,
callExtData[0],
callExtData[1],
warnAboutBudgetAndSchedule
]);
}
}
}
I don't really get why it's not working, considering I am declaring the array at the beginning. It's also worth noting that I did declare STRATEGISTS as a multi-dimensional array, like this:
var STRATEGISTS = [
['346-963-8912','Brizza','Arcadio'],
['885-612-1069','Doria','Arcadio'],
['922-596-2785','Edgar','Arcadio']
]
Any ideas?
EDIT
As per request I added:
Logger.log(STRATEGISTS.length);
Logger.log(STRATEGISTS);
The first one logged 51, and the second one logged the variable as expected.
Thanks,
So thanks to Guffa I realized that even though I had broken the push statement into different lines, it was treated as one. I had thought the problem was with my .push implementation, but rather it was a problem with one of the variables being pushed.
It turns out I had missed a return on
var callExtData = checkCallExtensions(campaign);
and so callExtData was empty, hence undefined.
Thanks!

Categories

Resources