How to update description fields in jira4r gem - ruby-on-rails

I'm able to update the custom-field of a jira-ticket by using the following code.
a = Jira4R::V2::RemoteFieldValue.new
a.id = "customfield_10000"
a.values = 'blah'
b = Jira4R::V2::RemoteFieldValue.new
b.id = "customfield_10022"
b.values = 'test'
ticket = jira.getIssue('blah-105')
jira.updateIssue(ticket.key, [a, b])
However, I am unable to update the description field using the same method.
Help would be appreciated.

finally found simple solution.
a = Jira4R::V2::RemoteFieldValue.new
a.id = "description" #id of description field
a.values = 'custom value'
ticket = jira.getIssue('TST-164')
jira.updateIssue(ticket.key, [a])

Related

Couldn't find GaBadge with 'id'=3

I am getting this error couldn't find id with id = '' i dont know how to fix it if any know how to fix it please tell me
#req2 = ActiveSupport::JSON.decode(#req)
##req3 = JSON.parse(#req2)
##reqId = #req3
#reqId = #req2[0]
#req3 = JSON.parse(#reqId)
#req3.each do |item|
#id = item['id']
#id = GaBadge.find(#id)
if #id.present?
#id.destroy
end
##obj = #id.destroy
end
I think, you are assigning value to #id as string.
Just try this,
#id = GaBadge.find_by_id(#id.to_i)
Error says GaBadge's table not having any record with id = 3, use
GaBadge.find_by_id(#id)
it will return nil instead of error.
Change your loop to
#req3.each do |item|
#id = item['id']
#ga_badge = GaBadge.find_by_id(#id.to_i)
unless #ga_badge.nil?
#ga_badge.destroy
end
end
i add .int and fixed
#req3.each do |item|
#id = item['id']
#ga_badge = GaBadge.find_by_id(#id.to_i)
unless #ga_badge.nil?
#ga_badge.destroy
end
end

How to get value from custom profile field in moodle in code?

How to get value from custom profile field in moodle?
i want to include the profile field in user.php
If you want to load all the user profile fields, then you can start with a user object
$user = $DB->get_record('user', array('id' => $userid));
and then call
profile_load_custom_fields($user);
to fill in the $user->profile with an array of all the custom fields.
Alternatively, you can get the contents of a single profile field via:
$sql = "SELECT ud.data
FROM {user_info_data} ud
JOIN {user_info_field} uf ON uf.id = ud.fieldid
WHERE ud.userid = :userid AND uf.shortname = :fieldname";
$params = array('userid' => $userid, 'fieldname' => 'NameOfCustomField');
$fieldvalue = $DB->get_field_sql($sql, $params);
Note this code is written off the top of my head and untested, so it may have some typos in it.
You can use:
$Data = $USER->profile['YourCustomField'];
I finally made it!!!
$sql = 'SELECT DISTINCT u.id AS userid, u.username, uif.shortname, uid.data FROM prefix_user u JOIN prefix_user_info_data as uid on uid.userid = u.id JOIN prefix_user_info_field as uif on uid.fieldid = uif.id JOIN prefix_user_enrolments ue ON ue.userid = u.id JOIN prefix_enrol e
ON e.id = ue.enrolid JOIN prefix_role_assignments ra ON ra.userid = u.id JOIN prefix_context ct ON ct.id = ra.contextid AND
ct.contextlevel = 50 JOIN prefix_course c ON c.id = ct.instanceid AND e.courseid = c.id JOIN prefix_role r ON r.id = ra.roleid
where uif.shortname = \'fieldname\' and u.id ='.$userid;
$records = $DB->get_recordset_sql($sql, array(), $params=null, $limitfrom=0, $limitnum=0);
foreach($records as $record){
$user['fieldname'] = $record->data;
}
custom fields are stored in 'user_info_field' table and data for each field and user are stored in 'user_info_data' table then you should know your fieldid in database and select data based on this id:
$field = $DB->get_record('user_info_field', array('shortname' => 'customfieldshortname'));
$fieldvalues = $DB->get_records('user_info_data',array('fieldid' => $field->id));
i hope my solutions help anybody:
need this lib
require_once($CFG->dirroot.'/user/profile/lib.php');
and now you can use:
profile_load_data($USER);
$USER->profile_field_%your_field_name%
example $USER->profile_field_HaveAnotherGradeBook;

how to convert sql query in ruby and rails?

SELECT A.FirstName, A.LastName, B.PatientId, B.RoomNumber, B.AdmissionDate, B.DischargeDate, B.MeasureCategory
FROM DimPatient A, DimPatientStay B
WHERE A.Id = B.PatientId AND A.FirstName = 'Anuj' AND B.MeasureCategory = 'ED'
hi some updation for this
i solved this prob by
MODELNAME.find_by_sql("your sql query")
You can try this to find the result from sql query in Rails
query_params = Hash.new
sql_query = "SELECT A.FirstName, A.LastName, B.PatientId, B.RoomNumber, B.AdmissionDate, B.DischargeDate, B.MeasureCategory
FROM DimPatient A, DimPatientStay B
WHERE A.Id = B.PatientId AND A.FirstName = :first_name AND B.MeasureCategory = :measure_category"
query_params[:first_name] = first_name
query_params[:measure_category] = measure_category
#query_results = ActiveRecord::Base.connection.select_all(
ActiveRecord::Base.send("sanitize_sql_array",[sql_query, query_params] )
)
I guess you could try:
ActiveRecord::Base.connection().execute(#your_sql_here)
Suppose A is one class and B is another, you should use includes as following:
A.includes(:b).where(...) # add you condition in where
I suggest to check good video tutorials of ActiveRecord here

Rails Nested Query

I have follow query
notes = Note.where('notes.id IN
(
SELECT "notes"."id" FROM "notes"
WHERE "notes"."circle_id" = ?
)
OR notes.id IN
(
SELECT "notes"."id" FROM "notes"
INNER JOIN "circles_dreams"
ON "circles_dreams"."dream_id" = "notes"."dream_id"
WHERE "circles_dreams"."circle_id" = ?
)', #circle.id, #circle.id)
How to simplify this query?
Thanks.
First of all you can collect all needed notes id.
I supposed to think what you already have relations between Note and CirclesDream
note_ids = Note.where(circle_id: #circle.id).pluck(:id) # your first SELECT
dream_ids = CirclesDream.where(id: #circle.id).pluck(:note_id) # your second SELECT
notes_ids = note_ids | dreams_ids # combine them
notes = Note.where(id: notes_ids) # Now your
upd: I've just fixed typo. Changed id to note_id in second request
Try this
note_ids = Note.where('circle_id = ?', #circle.id).pluck(:id)
dream_note_ids = Note.joins(:circle_dreams).where('circle_dreams.circle_id = ?', #circle.id).plunk(:note_id)
notes_ids = note_ids | dream_note_ids
If your circle_dreams table can contain records having note_id = null, then you have to apply join. So i think this will work in your case....

Need help in transforming this SQL statement to GORM

select
b.security_type,
b.symbol,
b.security_description,
b.trade_date_qty as 'axys_qty',
c.trade_date_qty as 'fidelity_qty',
c.trade_date_qty - b.trade_date_qty as 'qty_diff',
b.cost_basis as 'axys_cost',
c.cost_basis as 'fidelity_cost',
c.cost_basis - b.cost_basis as 'cost_diff'
from
account a
inner join advent_position b on a.fixed_account_number = b.account_number
inner join fidelity_position c on a.fixed_account_number = c.account_number and b.symbol = c.symbol
where
b.account_number = '636296651'
Basically, I have the ff. domains: Account, AdventPosition, FidelityPosition. I haven't set the relationship yet. I'm just wondering if there's a way to replicate the logic above using Criteria or HQL. Forgive me, I'm still new to Grails.
Thank you for any leads on this.
It'd be something close to this:
String hql = '''
select
b.securityType,
b.symbol,
b.securityDescription,
b.tradeDateQty,
c.tradeDateQty,
c.tradeDateQty - b.tradeDateQty,
b.costBasis,
c.costBasis,
c.costBasis - b.costBasis
from
Account a, AdventPosition b, FidelityPosition c
where
a.fixedAccountNumber = b.accountNumber
and a.fixedAccountNumber = c.accountNumber
and b.symbol = c.symbol
and b.accountNumber = :accountNumber
'''
def accountNumber = '636296651'
def results = Account.executeQuery(hql, [accountNumber: accountNumber])
The results will be an ArrayList of Object[], so you can iterate it with something like
for (row in results) {
def securityType = row[0]
def symbol = row[1]
def securityDescription = row[2]
def axys_qty = row[3]
def fidelity_qty = row[4]
def qty_diff = row[5]
def axys_cost = row[6]
def fidelity_cost = row[7]
def cost_diff = row[8]
}
I replaced the hard-coded account number with a named parameter; you can use regular ? like in SQL if you prefer and run 'def results = Account.executeQuery(hql, [accountNumber])', and of course if you intented it to be hard-coded then restore that and don't pass in the 2nd parameter, just run 'def results = Account.executeQuery(hql)'
just sharing the solution that I came up (while waiting for an answer :P) but note that the previous answer is way much better and faster:
def acc = Account.findByFixedAccountNumber('636296651')
List advPos = AdventPosition.findAllByAccountNumber('636296651')
List fidPos = advPos.collect {
FidelityPosition.findAllByAccountNumberAndSymbol('636296651', it.symbol)
}
def item = [:]
def res = []
def limit = advPos.size() - 1
for(i in 0..limit){
item.security_type = advPos[i].securityType
item.symbol = advPos[i].symbol
item.security_description = advPos[i].securityDescription
item.axys_qty = advPos[i].tradeDateQty
item.fidelity_qty = fidPos[i].tradeDateQty
item.qty_diff = item.fidelity_qty - item.axys_qty
item.axys_cost = advPos[i].costBasis
item.fidelity_cost = fidPos[i].costBasis
item.cost_diff = item.fidelity_cost - item.axys_cost
res.add(item)
}

Resources